public void ParallelGetChildrenTest() { MusicObject[] testObjects = new MusicObject[5]; testObjects[0] = new Keystroke(Tone.A, 2); testObjects[1] = new Pause(1); testObjects[2] = new Keystroke(Tone.B, 3); testObjects[3] = new Pause(1); testObjects[4] = new Keystroke(Tone.D, 5); List <SingleBeat> sTestList = new List <SingleBeat>(); ParallelMusicCollection sTestCollection = new ParallelMusicCollection(testObjects); IOrchestra testOrc = Substitute.For <IOrchestra>(); Instrument i = new Instrument(testOrc, InstrumentType.AcousticBass, new Scale()); sTestList.AddRange(sTestCollection.GetChildren(i, 1)); double testDouble = 1; foreach (SingleBeat sb in sTestList) { if (sb.ToneStartTime != testDouble && (sb.ToneVelocity != 0xff && sb.Tone != 0xff)) { Assert.Fail(); } } }
public void ParallelMusicCollectionTest() { MusicObject[] testObjects = new MusicObject[5]; testObjects[0] = new Keystroke(Tone.A, 2); testObjects[1] = new Keystroke(Tone.C, 4); testObjects[2] = new Keystroke(Tone.B, 3); testObjects[3] = new Keystroke(Tone.E, 1); testObjects[4] = new Keystroke(Tone.D, 5); ParallelMusicCollection pM = new ParallelMusicCollection(testObjects); Assert.IsTrue(pM.Contains(testObjects[0]) && pM.Contains(testObjects[1]) && pM.Contains(testObjects[2]) && pM.Contains(testObjects[3]) && pM.Contains(testObjects[4])); }
static void Main() { int bpm = 30; //Tempo of the music. Beats per minute. //Like most old western music, this is played in the A minor scale. //Note that as the tone enum starts at C, tones A and B are part of the lower octave. Tone[] majorScaleTones = { Tone.A - 12, Tone.B - 12, Tone.C, Tone.D, Tone.E, Tone.F, Tone.G }; Scale majorScale = new Scale(majorScaleTones); //The left hand is lowered by 1 octave. Scale loweredMajorScale = new Scale(majorScaleTones.Select(x => x - 12).ToArray()); //We will be using these constants a lot. double eigth = 1 / 8.0; byte baseVelocity = 50; //To play music, first we need an orchestra with access to an output. Orchestra o = new Orchestra(new WinmmOut(0, bpm)); //The piece should be played on a grand piano. Let's just get one. Instrument piano = o.AddInstrument(InstrumentType.AccousticGrandPiano, majorScale, 0); //---------------------------- // Creating the right hand: //---------------------------- //The treble clef shows the position of the G //(which has index 6 in majorScale) // so by counting a note's offset from the G // and adding the value corresponding to G in the scale // you get the tone you want. int trebleClef = majorScale.Interval(Tone.G); //Making all six bars: MusicObject rBar0 = //It seems, the first bar is only two eigths long. //The two notes have the same duration and velocity, so we are using a helper class.(The zero means the sustain pedal is not used.) SimilarNotes(eigth, baseVelocity, 0, majorScale[5 + trebleClef], majorScale[4 + trebleClef] + 1); //The ♯ elevates all tones on the line with 1 until cancelled by a ♮ or the bar ends. MusicObject rBar1And5 = SimilarNotes(eigth, baseVelocity, 0, majorScale[5 + trebleClef], majorScale[4 + trebleClef] + 1, majorScale[5 + trebleClef], majorScale[2 + trebleClef], majorScale[4 + trebleClef], majorScale[3 + trebleClef]); MusicObject rBar2 = new SequentialMusicList ( new Note(majorScale[1 + trebleClef], eigth * 2, baseVelocity), new Pause(eigth), SimilarNotes(eigth, baseVelocity, 0, majorScale[-4 + trebleClef], majorScale[-2 + trebleClef], majorScale[1 + trebleClef]) ); MusicObject rBar3 = new SequentialMusicList ( new Note(majorScale[2 + trebleClef], eigth * 2, baseVelocity), new Pause(eigth), SimilarNotes(eigth, baseVelocity, 0, majorScale[-2 + trebleClef], majorScale[0 + trebleClef] + 1, majorScale[2 + trebleClef]) ); MusicObject rBar4 = new SequentialMusicList ( new Note(majorScale[3 + trebleClef], eigth * 2, baseVelocity), new Pause(eigth), SimilarNotes(eigth, baseVelocity, 0, majorScale[-2 + trebleClef], majorScale[5 + trebleClef], majorScale[4 + trebleClef] + 1) ); //rBar5 is already accounted for //The whole right hand. MusicObject rightHand = new SequentialMusicList(rBar0, rBar1And5, rBar2, rBar3, rBar4, rBar1And5); //---------------------------- // Creating the left hand: //---------------------------- //The bass clef shows the position of the F //(which has index 5 in majorScale) // so by counting a note's offset from the F // and adding the value corresponding to F in the scale // you get the tone you want. int bassClef = loweredMajorScale.Interval(Tone.F); //Making all six bars: MusicObject lBar0 = new Pause(eigth * 2); MusicObject lBar1And5 = new Pause(eigth * 6); MusicObject lBar2And4 = new SequentialMusicList ( SimilarNotes(eigth, baseVelocity, 6, //These notes should be sustained for the rest of the bar. loweredMajorScale[-5 + bassClef], loweredMajorScale[-1 + bassClef], loweredMajorScale[2 + bassClef]), new Pause(eigth), new Pause(eigth * 2) ); MusicObject lBar3 = new SequentialMusicList ( SimilarNotes(eigth, baseVelocity, 6, //These notes should be sustained for the rest of the bar. loweredMajorScale[-8 + bassClef], loweredMajorScale[-1 + bassClef], loweredMajorScale[1 + bassClef] + 1), new Pause(eigth), new Pause(eigth * 2) ); //lBar4 is already accounted for. //lBar5 is already accounted for. //The whole left hand. MusicObject leftHand = new SequentialMusicList(lBar0, lBar1And5, lBar2And4, lBar3, lBar2And4, lBar1And5); //---------------------------- // Ready to play: //---------------------------- //The two hands should start playing at the same time: ParallelMusicCollection FurEliseIntro = new ParallelMusicCollection(leftHand, rightHand); //And then we just start it. piano.Play(FurEliseIntro); o.WaitForFinished(); Console.ReadLine(); }