using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using Buffer = Microsoft.DirectX.DirectSound.SecondaryBuffer;
using System.Threading;
namespace Bluebird
{
///
/// Summary description for bassChoices.
///
public class bassChoices : System.Windows.Forms.Form {
private Device ApplicationDevice;
private SecondaryBuffer soundBuffer;
private int curMeasure = 0;
private ArrayList measures;
private DisplayPanel myDisplayPanel;
private int curClip;
private System.Windows.Forms.Button Cancel;
private System.Windows.Forms.Button Clip1;
private System.Windows.Forms.Button Clip2;
private System.Windows.Forms.Button Clip3;
private System.Windows.Forms.Button Clip4;
private System.Windows.Forms.Button Clip5;
private System.Windows.Forms.Button Clip6;
private System.Windows.Forms.Button Clip7;
private System.Windows.Forms.Button Clip8;
private Thread soundThread;
private String curWav;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public bassChoices(int curM, ArrayList meas, DisplayPanel dp, int cc) {
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
curMeasure = curM;
measures = meas;
myDisplayPanel = dp;
curClip = cc;
ApplicationDevice = new Device();
ApplicationDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing ) {
killSound();
if( disposing ) {
if(components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent() {
this.Clip1 = new System.Windows.Forms.Button();
this.Clip2 = new System.Windows.Forms.Button();
this.Clip3 = new System.Windows.Forms.Button();
this.Clip4 = new System.Windows.Forms.Button();
this.Cancel = new System.Windows.Forms.Button();
this.Clip8 = new System.Windows.Forms.Button();
this.Clip7 = new System.Windows.Forms.Button();
this.Clip6 = new System.Windows.Forms.Button();
this.Clip5 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// Clip1
//
this.Clip1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip1.Location = new System.Drawing.Point(8, 8);
this.Clip1.Name = "Clip1";
this.Clip1.Size = new System.Drawing.Size(136, 80);
this.Clip1.TabIndex = 1;
this.Clip1.Text = "Bass Funk 1";
this.Clip1.Click += new System.EventHandler(this.Button_Click);
this.Clip1.Enter += new System.EventHandler(this.Button_Enter);
//
// Clip2
//
this.Clip2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip2.Location = new System.Drawing.Point(152, 8);
this.Clip2.Name = "Clip2";
this.Clip2.Size = new System.Drawing.Size(136, 80);
this.Clip2.TabIndex = 2;
this.Clip2.Text = "Bass Funk 2";
this.Clip2.Click += new System.EventHandler(this.Button_Click);
this.Clip2.Enter += new System.EventHandler(this.Button_Enter);
//
// Clip3
//
this.Clip3.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip3.Location = new System.Drawing.Point(296, 8);
this.Clip3.Name = "Clip3";
this.Clip3.Size = new System.Drawing.Size(136, 80);
this.Clip3.TabIndex = 3;
this.Clip3.Text = "Bass Funk 3";
this.Clip3.Click += new System.EventHandler(this.Button_Click);
this.Clip3.Enter += new System.EventHandler(this.Button_Enter);
//
// Clip4
//
this.Clip4.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip4.Location = new System.Drawing.Point(440, 8);
this.Clip4.Name = "Clip4";
this.Clip4.Size = new System.Drawing.Size(136, 80);
this.Clip4.TabIndex = 4;
this.Clip4.Text = "Bass Funk 4";
this.Clip4.Click += new System.EventHandler(this.Button_Click);
this.Clip4.Enter += new System.EventHandler(this.Button_Enter);
//
// Cancel
//
this.Cancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Cancel.Location = new System.Drawing.Point(440, 184);
this.Cancel.Name = "Cancel";
this.Cancel.Size = new System.Drawing.Size(136, 80);
this.Cancel.TabIndex = 9;
this.Cancel.Text = "Cancel";
this.Cancel.Click += new System.EventHandler(this.Button_Click);
this.Cancel.Enter += new System.EventHandler(this.Button_Enter);
//
// Clip8
//
this.Clip8.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip8.Location = new System.Drawing.Point(440, 96);
this.Clip8.Name = "Clip8";
this.Clip8.Size = new System.Drawing.Size(136, 80);
this.Clip8.TabIndex = 8;
this.Clip8.Text = "Bass Rock 4";
this.Clip8.Click += new System.EventHandler(this.Button_Click);
this.Clip8.Enter += new System.EventHandler(this.Button_Enter);
//
// Clip7
//
this.Clip7.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip7.Location = new System.Drawing.Point(296, 96);
this.Clip7.Name = "Clip7";
this.Clip7.Size = new System.Drawing.Size(136, 80);
this.Clip7.TabIndex = 7;
this.Clip7.Text = "Bass Rock 3";
this.Clip7.Click += new System.EventHandler(this.Button_Click);
this.Clip7.Enter += new System.EventHandler(this.Button_Enter);
//
// Clip6
//
this.Clip6.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip6.Location = new System.Drawing.Point(152, 96);
this.Clip6.Name = "Clip6";
this.Clip6.Size = new System.Drawing.Size(136, 80);
this.Clip6.TabIndex = 6;
this.Clip6.Text = "Bass Rock 2";
this.Clip6.Click += new System.EventHandler(this.Button_Click);
this.Clip6.Enter += new System.EventHandler(this.Button_Enter);
//
// Clip5
//
this.Clip5.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Clip5.Location = new System.Drawing.Point(8, 96);
this.Clip5.Name = "Clip5";
this.Clip5.Size = new System.Drawing.Size(136, 80);
this.Clip5.TabIndex = 5;
this.Clip5.Text = "Bass Rock 1";
this.Clip5.Click += new System.EventHandler(this.Button_Click);
this.Clip5.Enter += new System.EventHandler(this.Button_Enter);
//
// bassChoices
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(584, 270);
this.Controls.Add(this.Clip8);
this.Controls.Add(this.Clip7);
this.Controls.Add(this.Clip6);
this.Controls.Add(this.Clip5);
this.Controls.Add(this.Cancel);
this.Controls.Add(this.Clip4);
this.Controls.Add(this.Clip3);
this.Controls.Add(this.Clip2);
this.Controls.Add(this.Clip1);
this.Name = "bassChoices";
this.Text = "BassChoices";
this.ResumeLayout(false);
}
#endregion
private void Button_Click(object sender, System.EventArgs e) {
Clip myClip;
String buttonName = ((Button)sender).Name;
switch(buttonName) {
case "Clip1":
myClip = new Clip( ApplicationDevice, "Bass Funk 1", "bassFunk1.wav", "clipFunk.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Clip2":
myClip = new Clip( ApplicationDevice, "Bass Funk 2", "bassFunk2.wav", "clipFunk.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Clip3":
myClip = new Clip( ApplicationDevice, "Bass Funk 3", "bassFunk3.wav", "clipFunk.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Clip4":
myClip = new Clip( ApplicationDevice, "Bass Funk 4", "bassFunk4.wav", "clipFunk.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Clip5":
myClip = new Clip( ApplicationDevice, "Bass Rock 1", "bassRock01.wav", "clipRock.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Clip6":
myClip = new Clip( ApplicationDevice, "Bass Rock 2", "bassRock02.wav", "clipRock.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Clip7":
myClip = new Clip( ApplicationDevice, "Bass Rock 3", "bassRock03.wav", "clipRock.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Clip8":
myClip = new Clip( ApplicationDevice, "Bass Rock 4", "bassRock04.wav", "ClipRock.wav" );
((Measure)measures[curMeasure]).addClip(myClip);
break;
case "Cancel":
break;
}
refresh();
this.Close();
}
private void Button_Enter(object sender, System.EventArgs e) {
killSound();
String buttonName = ((Button)sender).Name;
switch(buttonName) {
case "Clip1":
curWav = "bassFunk1.wav";
soundBuffer = new SecondaryBuffer( "clipFunk.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Clip2":
curWav = "bassFunk2.wav";
soundBuffer = new SecondaryBuffer( "clipFunk.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Clip3":
curWav = "bassFunk3.wav";
soundBuffer = new SecondaryBuffer( "clipFunk.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Clip4":
curWav = "bassFunk4.wav";
soundBuffer = new SecondaryBuffer( "clipFunk.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Clip5":
curWav = "bassRock01.wav";
soundBuffer = new SecondaryBuffer( "clipRock.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Clip6":
curWav = "bassRock02.wav";
soundBuffer = new SecondaryBuffer( "clipRock.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Clip7":
curWav = "bassRock03.wav";
soundBuffer = new SecondaryBuffer( "clipRock.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Clip8":
curWav = "bassRock04.wav";
soundBuffer = new SecondaryBuffer( "clipRock.wav", ApplicationDevice );
soundThread = new Thread(new ThreadStart(playSound));
soundThread.Start();
break;
case "Cancel":
soundBuffer = new SecondaryBuffer( "instrumentCancel.wav", ApplicationDevice );
break;
}
soundBuffer.Play(0,0);
}
private void playSound() {
if(soundBuffer != null) {
try{
while(soundBuffer.Status.Playing){}
}
catch{
}
}
if(curWav != null) { //for clicking
soundBuffer = new SecondaryBuffer( curWav, ApplicationDevice );
soundBuffer.Play(0, 0);
while(soundBuffer.Status.Playing){}
}
}
private void refresh()
{
myDisplayPanel.update(measures, curMeasure, curClip);
myDisplayPanel.Invalidate();
myDisplayPanel.Update();
}
private void killSound() {
if( soundBuffer != null ) {
soundBuffer.Dispose();
soundBuffer = null;
}
if(soundThread != null) {
soundThread.Abort();
if(soundThread.ThreadState == ThreadState.Suspended)
soundThread.Abort();
}
}
}
}