using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectSound;
using Buffer = Microsoft.DirectX.DirectSound.SecondaryBuffer;
using System.Threading;
namespace Bluebird
{
///
/// Welcome to Bluebird.
/// April 29, 2004
/// Elise London
/// Jasen Hoover
/// Konrad Reszka
///
public class BlueBird : System.Windows.Forms.Form {
//public variables to constantly tell display panel what to draw
public ArrayList measures;
public int curMeasure = 0;
public int curClip = 0;
bool isPlaying = false;
int STARTNUMMEASURES = 1;
private Buffer[] below20Buffers;
private Buffer[] tensBuffers;
private Buffer[] hundredsBuffers;
private Buffer and;
//Thread used for playing to be able to wait for user IO at the same time
Thread playThread;
Thread measureThread;
//Buffer for all cues
private SecondaryBuffer soundBuffer;
private SecondaryBuffer measureBuffer;
private SecondaryBuffer instructions;
private Device ApplicationDevice;
private string PathSoundFile = string.Empty;
//Instrument and Control buttons
public System.Windows.Forms.Button Guitar;
private System.Windows.Forms.Button Bass;
private System.Windows.Forms.Button Vocals;
private System.Windows.Forms.Button Keyboard;
private System.Windows.Forms.GroupBox Instruments;
private System.Windows.Forms.Button PlayStop;
private System.Windows.Forms.Button Insert;
private System.Windows.Forms.Button Last;
private System.Windows.Forms.Button PlaySingle;
private System.Windows.Forms.GroupBox ControlsGroup;
private System.Windows.Forms.GroupBox Measures;
private System.Windows.Forms.Button Drum;
private System.Windows.Forms.Button First;
private System.Windows.Forms.Button StartOver;
private System.Windows.Forms.Button Quit;
private System.Windows.Forms.Button Delete;
private System.Windows.Forms.Button Loop;
//generates the display
private DisplayPanel myDisplayPanel;
///
/// Required designer variable
///
private System.ComponentModel.Container components = null;
public BlueBird()
{
//start with STARTNUMMEASURES as non null measures
measures = new ArrayList(STARTNUMMEASURES);
for(int i = 0; i < STARTNUMMEASURES; i++)
{
Measure newMeasure = new Measure();
measures.Insert(i, newMeasure);
}
//
// Required for Windows Form Designer support
//
InitializeComponent();
Application.AddMessageFilter(new TestMessageFilter(this));
this.IsAccessible = true;
foreach (Control current in this.Controls)
current.IsAccessible = true;
//
// TODO: Add any constructor code after InitializeComponent call
//
myDisplayPanel = new DisplayPanel(measures, curMeasure);
this.Measures.Controls.Add(this.myDisplayPanel);
this.myDisplayPanel.Location = new System.Drawing.Point(16, 24);
this.myDisplayPanel.Name = "myDisplayPanel";
this.myDisplayPanel.Size = new System.Drawing.Size(824, 168);
this.myDisplayPanel.TabIndex = 0;
ApplicationDevice = new Device();
ApplicationDevice.SetCooperativeLevel(this, CooperativeLevel.Priority);
soundBuffer = new SecondaryBuffer( "displayBlank.wav", ApplicationDevice );
below20Buffers = new Buffer[20];
tensBuffers = new Buffer[8];
hundredsBuffers = new Buffer[2];
this.initNumberBuffers();
and = new Buffer( "numberAnd.wav", ApplicationDevice );
measureBuffer = new SecondaryBuffer( "displayMeasure.wav", ApplicationDevice);
instructions = new SecondaryBuffer( "Instructions.wav", ApplicationDevice );
instructions.Play(0,BufferPlayFlags.Default);
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if(playThread != null)
playThread.Abort();
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
/*Handles Key events from User
* Left Arrow - Shifts left a measure
* Right Arrow - Shifts right a measure
* Up Arrow - Shifts up a clip
* Down Arrow - Shifts down a clip
* Enter - Deletes the current highlighted clip
* J - Plays the current highlighted clip
* Escape - Stops any cues from playing
* H - HELP, plays instructions for shortcut keys
* S - Stops and Starts Play
* I - Reads the instructions
* Q - Quits
* D - Deletes the current measure
* C - Plays current measure
*/
public bool HandleKeys(Keys keyData)
{
bool ret = true;
switch (keyData)
{
case Keys.Left: //shifts a measure to the left
shiftLeft();
break;
case Keys.Right: //shifts a measure to the right
shiftRight();
break;
case Keys.Up: //shifts up one clip
shiftUp();
break;
case Keys.Down: //shifts down one clip
shiftDown();
break;
case Keys.Enter: //deletes a clip
deleteClip();
break;
case Keys.J: //plays the currently selected clip
jPressed();
break;
case Keys.Escape: //stops audio cues
this.clearBuffer();
this.clearInstructions();
break;
case Keys.H: //Help: plays short cut key instrs.
shortCuts(); //NEED TO DO THIS~!!@!#$
break;
case Keys.S: //starts or stops the music
playStop();
break;
case Keys.I: //reads the instructions
readInstructions();
break;
case Keys.D: //deletes a measure
deleteMeasure();
break;
case Keys.Q: //quits
this.Dispose(true);
break;
case Keys.C: //plays the current measure
this.playCur();
break;
default:
ret = base.IsInputKey(keyData);
break;
}
return ret;
}
#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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(BlueBird));
this.Guitar = new System.Windows.Forms.Button();
this.Bass = new System.Windows.Forms.Button();
this.Keyboard = new System.Windows.Forms.Button();
this.Vocals = new System.Windows.Forms.Button();
this.Instruments = new System.Windows.Forms.GroupBox();
this.Drum = new System.Windows.Forms.Button();
this.ControlsGroup = new System.Windows.Forms.GroupBox();
this.Loop = new System.Windows.Forms.Button();
this.Quit = new System.Windows.Forms.Button();
this.Delete = new System.Windows.Forms.Button();
this.StartOver = new System.Windows.Forms.Button();
this.PlaySingle = new System.Windows.Forms.Button();
this.Last = new System.Windows.Forms.Button();
this.Insert = new System.Windows.Forms.Button();
this.PlayStop = new System.Windows.Forms.Button();
this.First = new System.Windows.Forms.Button();
this.Measures = new System.Windows.Forms.GroupBox();
this.Instruments.SuspendLayout();
this.ControlsGroup.SuspendLayout();
this.SuspendLayout();
//
// Guitar
//
this.Guitar.AccessibleDescription = "Guitar";
this.Guitar.AccessibleName = "Guitar";
this.Guitar.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Guitar.Location = new System.Drawing.Point(16, 24);
this.Guitar.Name = "Guitar";
this.Guitar.Size = new System.Drawing.Size(168, 168);
this.Guitar.TabIndex = 0;
this.Guitar.Text = "Guitar";
this.Guitar.Click += new System.EventHandler(this.Instrument_Click);
this.Guitar.Enter += new System.EventHandler(this.Button_Enter);
//
// Bass
//
this.Bass.AccessibleDescription = "Bass";
this.Bass.AccessibleName = "Bass";
this.Bass.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Bass.Location = new System.Drawing.Point(176, 24);
this.Bass.Name = "Bass";
this.Bass.Size = new System.Drawing.Size(168, 168);
this.Bass.TabIndex = 1;
this.Bass.Text = "Bass";
this.Bass.Click += new System.EventHandler(this.Instrument_Click);
this.Bass.Enter += new System.EventHandler(this.Button_Enter);
//
// Keyboard
//
this.Keyboard.AccessibleDescription = "Keyboard";
this.Keyboard.AccessibleName = "Keyboard";
this.Keyboard.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Keyboard.Location = new System.Drawing.Point(520, 24);
this.Keyboard.Name = "Keyboard";
this.Keyboard.Size = new System.Drawing.Size(168, 168);
this.Keyboard.TabIndex = 3;
this.Keyboard.Text = "Keyboard";
this.Keyboard.Click += new System.EventHandler(this.Instrument_Click);
this.Keyboard.Enter += new System.EventHandler(this.Button_Enter);
//
// Vocals
//
this.Vocals.AccessibleDescription = "Vocals";
this.Vocals.AccessibleName = "Vocals";
this.Vocals.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Vocals.Location = new System.Drawing.Point(688, 24);
this.Vocals.Name = "Vocals";
this.Vocals.Size = new System.Drawing.Size(160, 168);
this.Vocals.TabIndex = 4;
this.Vocals.Text = "Misc";
this.Vocals.Click += new System.EventHandler(this.Instrument_Click);
this.Vocals.Enter += new System.EventHandler(this.Button_Enter);
//
// Instruments
//
this.Instruments.AccessibleDescription = "Here are the selections for the various sounds you can make!";
this.Instruments.AccessibleName = "Instruments";
this.Instruments.Controls.Add(this.Drum);
this.Instruments.Controls.Add(this.Guitar);
this.Instruments.Controls.Add(this.Vocals);
this.Instruments.Controls.Add(this.Bass);
this.Instruments.Controls.Add(this.Keyboard);
this.Instruments.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Instruments.Location = new System.Drawing.Point(16, 16);
this.Instruments.Name = "Instruments";
this.Instruments.Size = new System.Drawing.Size(864, 208);
this.Instruments.TabIndex = 5;
this.Instruments.TabStop = false;
this.Instruments.Text = "Instruments";
//
// Drum
//
this.Drum.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Drum.Location = new System.Drawing.Point(352, 24);
this.Drum.Name = "Drum";
this.Drum.Size = new System.Drawing.Size(168, 168);
this.Drum.TabIndex = 2;
this.Drum.Text = "Drums";
this.Drum.Click += new System.EventHandler(this.Instrument_Click);
this.Drum.Enter += new System.EventHandler(this.Button_Enter);
//
// ControlsGroup
//
this.ControlsGroup.Controls.Add(this.Loop);
this.ControlsGroup.Controls.Add(this.Quit);
this.ControlsGroup.Controls.Add(this.Delete);
this.ControlsGroup.Controls.Add(this.StartOver);
this.ControlsGroup.Controls.Add(this.PlaySingle);
this.ControlsGroup.Controls.Add(this.Last);
this.ControlsGroup.Controls.Add(this.Insert);
this.ControlsGroup.Controls.Add(this.PlayStop);
this.ControlsGroup.Controls.Add(this.First);
this.ControlsGroup.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ControlsGroup.Location = new System.Drawing.Point(16, 240);
this.ControlsGroup.Name = "ControlsGroup";
this.ControlsGroup.Size = new System.Drawing.Size(864, 136);
this.ControlsGroup.TabIndex = 6;
this.ControlsGroup.TabStop = false;
this.ControlsGroup.Text = "Controls";
//
// Loop
//
this.Loop.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Loop.Location = new System.Drawing.Point(192, 24);
this.Loop.Name = "Loop";
this.Loop.Size = new System.Drawing.Size(152, 40);
this.Loop.TabIndex = 7;
this.Loop.Text = "Loop";
this.Loop.Click += new System.EventHandler(this.Loop_Click);
this.Loop.Enter += new System.EventHandler(this.Button_Enter);
//
// Quit
//
this.Quit.AccessibleDescription = "Quit Button";
this.Quit.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Quit.Location = new System.Drawing.Point(648, 80);
this.Quit.Name = "Quit";
this.Quit.Size = new System.Drawing.Size(192, 40);
this.Quit.TabIndex = 14;
this.Quit.Text = "Quit";
this.Quit.Click += new System.EventHandler(this.Quit_Click);
this.Quit.Enter += new System.EventHandler(this.Button_Enter);
//
// Delete
//
this.Delete.AccessibleDescription = "Delete Single Measure";
this.Delete.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Delete.Location = new System.Drawing.Point(696, 24);
this.Delete.Name = "Delete";
this.Delete.Size = new System.Drawing.Size(144, 40);
this.Delete.TabIndex = 10;
this.Delete.Text = "Delete Single Measure";
this.Delete.Click += new System.EventHandler(this.Delete_Click);
//
// StartOver
//
this.StartOver.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.StartOver.Location = new System.Drawing.Point(440, 80);
this.StartOver.Name = "StartOver";
this.StartOver.Size = new System.Drawing.Size(192, 40);
this.StartOver.TabIndex = 13;
this.StartOver.Text = "Start Over";
this.StartOver.Click += new System.EventHandler(this.StartOver_Click);
this.StartOver.Enter += new System.EventHandler(this.Button_Enter);
//
// PlaySingle
//
this.PlaySingle.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.PlaySingle.Location = new System.Drawing.Point(360, 24);
this.PlaySingle.Name = "PlaySingle";
this.PlaySingle.Size = new System.Drawing.Size(152, 40);
this.PlaySingle.TabIndex = 8;
this.PlaySingle.Text = "Play Single Measure";
this.PlaySingle.Click += new System.EventHandler(this.PlaySingle_Click);
this.PlaySingle.Enter += new System.EventHandler(this.Button_Enter);
//
// Last
//
this.Last.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Last.Location = new System.Drawing.Point(232, 80);
this.Last.Name = "Last";
this.Last.Size = new System.Drawing.Size(192, 40);
this.Last.TabIndex = 12;
this.Last.Text = "Go to Last Measure";
this.Last.Click += new System.EventHandler(this.Last_Click);
this.Last.Enter += new System.EventHandler(this.Button_Enter);
//
// Insert
//
this.Insert.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Insert.Location = new System.Drawing.Point(528, 24);
this.Insert.Name = "Insert";
this.Insert.Size = new System.Drawing.Size(152, 40);
this.Insert.TabIndex = 9;
this.Insert.Text = "Insert Single Measure";
this.Insert.Click += new System.EventHandler(this.Insert_Click);
this.Insert.Enter += new System.EventHandler(this.Button_Enter);
//
// PlayStop
//
this.PlayStop.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.PlayStop.Location = new System.Drawing.Point(24, 24);
this.PlayStop.Name = "PlayStop";
this.PlayStop.Size = new System.Drawing.Size(152, 40);
this.PlayStop.TabIndex = 6;
this.PlayStop.Text = "Play";
this.PlayStop.Click += new System.EventHandler(this.PlayStop_Click);
this.PlayStop.Enter += new System.EventHandler(this.Button_Enter);
//
// First
//
this.First.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.First.Location = new System.Drawing.Point(24, 80);
this.First.Name = "First";
this.First.Size = new System.Drawing.Size(192, 40);
this.First.TabIndex = 11;
this.First.Text = "Go to First Measure";
this.First.Click += new System.EventHandler(this.First_Click);
this.First.Enter += new System.EventHandler(this.Button_Enter);
//
// Measures
//
this.Measures.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.Measures.Location = new System.Drawing.Point(16, 392);
this.Measures.Name = "Measures";
this.Measures.Size = new System.Drawing.Size(864, 208);
this.Measures.TabIndex = 7;
this.Measures.TabStop = false;
this.Measures.Text = "Measures";
//
// BlueBird
//
this.AccessibleDescription = "Main";
this.AccessibleName = "Main";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(896, 616);
this.Controls.Add(this.Measures);
this.Controls.Add(this.ControlsGroup);
this.Controls.Add(this.Instruments);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "BlueBird";
this.Text = "BlueBird";
this.Instruments.ResumeLayout(false);
this.ControlsGroup.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run(new BlueBird());
}
private void Instrument_Click(object sender, System.EventArgs e)
{
String buttonName = ((Button)sender).Name;
switch(buttonName)
{
case "Guitar":
guitarChoices newGuitarChoices = new guitarChoices(curMeasure,
measures, myDisplayPanel, curClip);
newGuitarChoices.Show();
break;
case "Bass":
bassChoices newBassChoices = new bassChoices(curMeasure,
measures, myDisplayPanel, curClip);
newBassChoices.Show();
break;
case "Drum":
drumChoices newDrumChoices = new drumChoices(curMeasure,
measures, myDisplayPanel, curClip);
newDrumChoices.Show();
break;
case "Keyboard":
keyboardChoices newKeyboardChoices = new keyboardChoices(curMeasure,
measures, myDisplayPanel, curClip);
newKeyboardChoices.Show();
break;
case "Vocals":
miscChoices newMiscChoices = new miscChoices(curMeasure,
measures, myDisplayPanel, curClip);
newMiscChoices.Show();
break;
}
myDisplayPanel.Invalidate();
myDisplayPanel.Update();
}
private void First_Click(object sender, System.EventArgs e)
{
curMeasure = 0;
refresh();
}
private void Last_Click(object sender, System.EventArgs e)
{
curMeasure = measures.Count-1;
refresh();
}
private void PlayStop_Click(object sender, System.EventArgs e)
{
if(PlayStop.Text.Equals("Play") && !isPlaying)
{
PlayStop.Text = "Stop";
playThread = new Thread(new ThreadStart(this.Play));
playThread.Start();
isPlaying = true;
}
else if(PlayStop.Text.Equals("Stop"))
{
playThread.Abort();
this.disposeBuffers();
PlayStop.Text = "Play";
isPlaying = false;
}
}
private void playStop()
{
if(PlayStop.Text.Equals("Play") && !isPlaying)
{
PlayStop.Text = "Stop";
playThread = new Thread(new ThreadStart(this.Play));
playThread.Start();
isPlaying = true;
}
else if(PlayStop.Text.Equals("Stop"))
{
playThread.Abort();
isPlaying = false;
this.disposeBuffers();
isPlaying = false;
PlayStop.Text = "Play";
deleteBlanks();
}
}
private void Insert_Click(object sender, System.EventArgs e)
{
insertMeasure();
}
private void PlaySingle_Click(object sender, System.EventArgs e)
{
playCur();
}
private void StartOver_Click(object sender, System.EventArgs e)
{
this.isPlaying = false;
if(playThread != null)
playThread.Abort();
this.disposeBuffers();
curMeasure = 0;
measures = new ArrayList(STARTNUMMEASURES);
for(int i = 0; i < STARTNUMMEASURES; i++)
{
Measure newMeasure = new Measure();
measures.Insert(i, newMeasure);
}
if(PlayStop.Text.Equals("Stop"))
PlayStop.Text = "Play";
if(Loop.Text.Equals("Stop"))
Loop.Text = "Loop";
refresh();
}
private void shiftLeft()
{
curClip = 0;
if(curMeasure != 0)
curMeasure--;
refresh();
playMeasureName();
}
private void shiftRight()
{
curClip = 0;
if(curMeasure <= (measures.Count))
curMeasure++;
if(curMeasure == (measures.Count))
{
Measure newMeasure = new Measure();
measures.Add(newMeasure);
}
refresh();
playMeasureName();
}
private void shiftUp()
{
if(curClip > 0)
curClip--;
if(((Measure)measures[curMeasure]).getClip(curClip) != null)
{
((Measure)measures[curMeasure]).getClip(curClip).playName();
}
refresh();
}
private void shiftDown()
{
if(((Measure)measures[curMeasure]).getNumClips() - 1 > curClip)
curClip++;
if(((Measure)measures[curMeasure]).getClip(curClip) != null) {
((Measure)measures[curMeasure]).getClip(curClip).playName();
}
refresh();
}
private void deleteClip()
{
if(((Measure)measures[curMeasure]).isEmpty() == false)
{
((Measure)measures[curMeasure]).deleteClip(curClip);
if(curClip == ((Measure)measures[curMeasure]).getNumClips())
shiftUp();
}
refresh();
System.Console.WriteLine(((Measure)measures[curMeasure]).getNumClips());
System.Console.WriteLine(curClip);
}
private void insertMeasure()
{
//creates the new measure
Measure newMeasure = new Measure();
measures.Insert(curMeasure, newMeasure);
refresh();
}
private void deleteMeasure()
{
//Disallowing deleting measure dynamically
if(!isPlaying){
//find last filled measure
int lastFilled = 0;
for(int i = 0; i < measures.Count; i++) {
if(((Measure)measures[i]).isEmpty() == false)
lastFilled = i;
}
//delete clips from measure to delete
if(((Measure)measures[curMeasure]).getNumClips() > 0) {
((Measure)measures[curMeasure]).deleteAllClips();
}
//delete the measure
measures.RemoveAt(curMeasure);
if((curMeasure == lastFilled && curMeasure > 0) ||
(curMeasure == measures.Count && curMeasure > 0)) {
shiftLeft();
}
else if(curMeasure == 0 && lastFilled == 0)
insertMeasure();
refresh();
}
}
public int getCurMeasure()
{
return curMeasure;
}
private void refresh()
{
myDisplayPanel.update(measures, curMeasure, curClip);
myDisplayPanel.Invalidate();
myDisplayPanel.Update();
}
private void jPressed() {
if(((Measure)measures[curMeasure]).isEmpty() == false) {
((Measure)measures[curMeasure]).getClip(curClip).playSound();
}
}
private void playMeasureName() {
if(!isPlaying) {
if(measureThread != null) {
measureThread.Abort();
try{if(measureThread.ThreadState == ThreadState.Suspended)
measureThread.Abort();
}
catch(ThreadStateException e){
System.Console.WriteLine(e.StackTrace);
}
}
measureThread = new Thread(new ThreadStart(this.playNumbers));
measureThread.Start();
}
}
private void Button_Enter(object sender, System.EventArgs e)
{
clearBuffer();
String buttonName = ((Button)sender).Name;
switch(buttonName)
{
case "Guitar":
soundBuffer = new SecondaryBuffer( "controlGuitarHighlighted.wav", ApplicationDevice );
break;
case "Bass":
soundBuffer = new SecondaryBuffer( "controlBassHighlighted.wav", ApplicationDevice );
break;
case "Vocals":
soundBuffer = new SecondaryBuffer( "controlMiscHighlighted.wav", ApplicationDevice );
break;
case "Keyboard":
soundBuffer = new SecondaryBuffer( "controlKeyboardsHighlighted.wav", ApplicationDevice );
break;
case "Drum":
soundBuffer = new SecondaryBuffer( "controlDrumsHighlighted.wav", ApplicationDevice );
break;
case "First":
soundBuffer = new SecondaryBuffer( "controlGotoFirstMeasure.wav", ApplicationDevice );
break;
case "Last":
soundBuffer = new SecondaryBuffer( "controlGotoLastMeasure.wav", ApplicationDevice );
break;
case "StartOver":
soundBuffer = new SecondaryBuffer( "controlStartOver.wav", ApplicationDevice );
break;
case "PlayStop":
if(PlayStop.Text.Equals("Play"))
soundBuffer = new SecondaryBuffer( "controlPlay.wav", ApplicationDevice );
else
soundBuffer = new SecondaryBuffer( "controlStop.wav", ApplicationDevice );
break;
case "Insert":
soundBuffer = new SecondaryBuffer( "controlInsertMeasure.wav", ApplicationDevice );
break;
case "PlaySingle":
soundBuffer = new SecondaryBuffer( "controlPlaySingleMeasure.wav", ApplicationDevice );
break;
case "Quit":
soundBuffer = new SecondaryBuffer( "controlQuit.wav", ApplicationDevice );
break;
case "Loop":
soundBuffer = new SecondaryBuffer( "controlLoop.wav", ApplicationDevice );
break;
}
if(soundBuffer != null)
soundBuffer.Play(0, BufferPlayFlags.Default);
}
private void clearBuffer()
{
if(soundBuffer != null)
{
soundBuffer.Dispose();
soundBuffer = null;
}
}
private void clearInstructions() {
if(instructions != null) {
instructions.Dispose();
instructions = null;
}
}
private void Delete_Click(object sender, System.EventArgs e) {
deleteMeasure();
}
private void Quit_Click(object sender, System.EventArgs e) {
this.Dispose(true);
}
private void Loop_Click(object sender, System.EventArgs e) {
if(Loop.Text.Equals("Loop") && !isPlaying) {
Loop.Text = "Stop";
playThread = new Thread(new ThreadStart(this.LoopPlay));
playThread.Start();
isPlaying = true;
}
else if(Loop.Text.Equals("Stop")) {
playThread.Abort();
this.disposeBuffers();
isPlaying = false;
Loop.Text = "Loop";
deleteBlanks();
}
}
private void Play()
{
curMeasure = 0;
refresh();
for(int i = 0; i < measures.Count; i++)
{
if(((Measure)measures[i]).isEmpty()) {
Clip newClip = new Clip(ApplicationDevice, "blank", "displayBlank.wav", "displayBlank.wav");
((Measure)measures[i]).addClip(newClip);
}
((Measure)measures[i]).play();
while(((Measure)measures[i]).stillPlaying())
{
//busy waiting
}
if(curMeasure < measures.Count-1)
shiftRight();
refresh();
}
PlayStop.Text = "Play";
deleteBlanks();
isPlaying = false;
}
private void LoopPlay() {
curMeasure = 0;
refresh();
int i = 0;
while(true) {
if(((Measure)measures[i]).isEmpty()) {
Clip newClip = new Clip(ApplicationDevice, "blank", "displayBlank.wav", "displayBlank.wav");
((Measure)measures[i]).addClip(newClip);
}
((Measure)measures[i]).play();
while(((Measure)measures[i]).stillPlaying()) {
//busy waiting
}
if(curMeasure < measures.Count-1)
shiftRight();
refresh();
i++;
if(i == measures.Count) {
deleteBlanks();
i = 0;
curMeasure = 0;
refresh();
}
}
}
private void disposeBuffers()
{
for(int i = 0; i < measures.Count; i++)
{
if(((Measure)measures[i]).isEmpty() == false )
((Measure)measures[i]).disposeAllBuffers();
}
}
private void shortCuts() {
instructions = new SecondaryBuffer( "shortcutInstructions.wav", ApplicationDevice );
instructions.Play(0, BufferPlayFlags.Default);
}
private void readInstructions() {
instructions = new SecondaryBuffer( "Instructions.wav", ApplicationDevice );
instructions.Play(0,BufferPlayFlags.Default);
}
private void deleteBlanks(){
for(int i = 0; i < measures.Count; i++) {
if(!((Measure)measures[i]).isEmpty() &&
((Measure)measures[i]).getClip(0).getName().Equals("blank")) {
((Measure)measures[i]).deleteClip(0);
}
refresh();
}
}
private void initNumberBuffers(){
this.below20Buffers[0] = new SecondaryBuffer( "numberZero.wav", ApplicationDevice );
this.below20Buffers[1] = new SecondaryBuffer( "numberOne.wav", ApplicationDevice );
this.below20Buffers[2] = new SecondaryBuffer( "numberTwo.wav", ApplicationDevice );
this.below20Buffers[3] = new SecondaryBuffer( "numberThree.wav", ApplicationDevice );
this.below20Buffers[4] = new SecondaryBuffer( "numberFour.wav", ApplicationDevice );
this.below20Buffers[5] = new SecondaryBuffer( "numberFive.wav", ApplicationDevice );
this.below20Buffers[6] = new SecondaryBuffer( "numberSix.wav", ApplicationDevice );
this.below20Buffers[7] = new SecondaryBuffer( "numberSeven.wav", ApplicationDevice );
this.below20Buffers[8] = new SecondaryBuffer( "numberEight.wav", ApplicationDevice );
this.below20Buffers[9] = new SecondaryBuffer( "numberNine.wav", ApplicationDevice );
this.below20Buffers[10] = new SecondaryBuffer( "numberTen.wav", ApplicationDevice );
this.below20Buffers[11] = new SecondaryBuffer( "numberEleven.wav", ApplicationDevice );
this.below20Buffers[12] = new SecondaryBuffer( "numberTwelve.wav", ApplicationDevice );
this.below20Buffers[13] = new SecondaryBuffer( "numberThirteen.wav", ApplicationDevice );
this.below20Buffers[14] = new SecondaryBuffer( "numberFourteen.wav", ApplicationDevice );
this.below20Buffers[15] = new SecondaryBuffer( "numberFifteen.wav", ApplicationDevice );
this.below20Buffers[16] = new SecondaryBuffer( "numberSixteen.wav", ApplicationDevice );
this.below20Buffers[17] = new SecondaryBuffer( "numberSeventeen.wav", ApplicationDevice );
this.below20Buffers[18] = new SecondaryBuffer( "numberEighteen.wav", ApplicationDevice );
this.below20Buffers[19] = new SecondaryBuffer( "numberNineteen.wav", ApplicationDevice );
this.tensBuffers[0] = new SecondaryBuffer( "numberTwenty.wav", ApplicationDevice );
this.tensBuffers[1] = new SecondaryBuffer( "numberThirty.wav", ApplicationDevice );
this.tensBuffers[2] = new SecondaryBuffer( "numberForty.wav", ApplicationDevice );
this.tensBuffers[3] = new SecondaryBuffer( "numberFifty.wav", ApplicationDevice );
this.tensBuffers[4] = new SecondaryBuffer( "numberSixty.wav", ApplicationDevice );
this.tensBuffers[5] = new SecondaryBuffer( "numberSeventy.wav", ApplicationDevice );
this.tensBuffers[6] = new SecondaryBuffer( "numberEighty.wav", ApplicationDevice );
this.tensBuffers[7] = new SecondaryBuffer( "numberNinety.wav", ApplicationDevice );
this.hundredsBuffers[0] = new Buffer( "numberOneHundred.wav", ApplicationDevice );
this.hundredsBuffers[1] = new Buffer( "numberTwoHundred.wav", ApplicationDevice );
}
private void playCur(){
((Measure)measures[curMeasure]).play();
}
private void playNumbers(){
clearBuffer();
soundBuffer = new SecondaryBuffer("displayMeasure.wav", ApplicationDevice);
soundBuffer.Play(0, BufferPlayFlags.Default);
while(soundBuffer.Status.Playing){}
int test = curMeasure;
if(curMeasure >= 200) { //100s place
test = test% 200;
this.hundredsBuffers[1].Play(0, BufferPlayFlags.Default);
while(hundredsBuffers[1].Status.Playing){}
if(test < 10 && test > 0) {
soundBuffer = new SecondaryBuffer( "numberAnd.wav", ApplicationDevice );
soundBuffer.Play(0,0);
while(soundBuffer.Status.Playing){}
}
}
else if(curMeasure >= 100) {
test = test%100;
this.hundredsBuffers[0].Play(0, BufferPlayFlags.Default);
while(hundredsBuffers[0].Status.Playing){}
if(test < 10 && test > 0) {
soundBuffer = new SecondaryBuffer( "numberAnd.wav", ApplicationDevice );
soundBuffer.Play(0,0);
while(soundBuffer.Status.Playing){}
}
}
if(test >= 20)
{ //10s place
for(int i = this.tensBuffers.Length+2; i >= 2; i--) {
if(test%(i*10) == 0 || test %(i*10) < 10) {
this.tensBuffers[i-2].Play(0, BufferPlayFlags.Default);
while(tensBuffers[i-2].Status.Playing){}
break;
}
}
}
else if(test > 9 && test < 20) { //if in the teens
for(int i = 10; i < this.below20Buffers.Length+10; i++) {
if(i%test == 0) {
this.below20Buffers[i].Play(0, BufferPlayFlags.Default);
while(this.below20Buffers[i].Status.Playing){}
break;
}
}
}
if((test < 10 && test%10 != 0) || test > 20) { //get 1's place
for(int i = 9; i >= 1; i--) {
if(i > 1) {
if((curMeasure%10)%i == 0) {
this.below20Buffers[i].Play(0, BufferPlayFlags.Default);
while(this.below20Buffers[i].Status.Playing){}
break;
}
}
}
if(curMeasure %10 != 0) {
if(curMeasure == 1 || 1%(curMeasure%10) == 0) {
this.below20Buffers[1].Play(0, BufferPlayFlags.Default);
while(this.below20Buffers[1].Status.Playing){}
}
}
}
if(curMeasure == 0) {
this.below20Buffers[0].Play(0, BufferPlayFlags.Default);
while(this.below20Buffers[0].Status.Playing){}
}
}
}
}