public void WithBaseToneTest(Tone tone, double duration) { ChordVariety acd = new ChordVariety(1, 4, 7); Orchestra orc = new Orchestra(NSubstitute.Substitute.For <IMidiOut>()); List <SingleBeat> v = acd.WithBaseTone(Tone.CSharp, 5).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList(); List <SingleBeat> comp = new List <SingleBeat>(); comp.AddRange(new Keystroke(tone, duration).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList()); comp.AddRange(new Keystroke(Tone.E, duration).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList()); comp.AddRange(new Keystroke(Tone.G, duration).GetChildren(orc.AddInstrument(InstrumentType.AccousticGrandPiano), 0).ToList()); CollectionAssert.AreEqual(comp, v); }
static void Main(string[] args) { Orchestra orchestra = new Orchestra(new WinmmOut(0, 70)); Instrument bagpipe = orchestra.AddInstrument(InstrumentType.BagPipe); bagpipe.Play(Tone.CSharp, 1); orchestra.WaitForFinished(); }
public void AddInstrumentTest(InstrumentType instrumentType, int octave = 3) { Orchestra orc = new Orchestra(Substitute.For <IMidiOut>(), 8); orc.AddInstrument(instrumentType, octave); bool test = orc.Instruments.ToList().Exists(item => (item.InstrumentType == instrumentType) && (item.Octave == octave)); Assert.IsTrue(test); }
public void AddInstrumentTest1() { Scale scale = new Scale(Tone.A, Tone.B, Tone.C); Orchestra orc = new Orchestra(Substitute.For <IMidiOut>(), 8); orc.AddInstrument(InstrumentType.Violin, scale, 5); bool test = orc.Instruments.ToList().Exists(item => (item.InstrumentType == InstrumentType.Violin) && (item.Octave == 5) && (item.Scale == scale)); Assert.IsTrue(test); }
public void QueueMusicTest() { using (WinmmOut winMM = new WinmmOut(0)) { Orchestra o = new Orchestra(winMM); Keystroke n = new Keystroke(Tone.C, 1000); Instrument i = o.AddInstrument(InstrumentType.AccousticGrandPiano); i.Play(n); Thread.Sleep(5000); } }
// This method initiates the music components. internal void MusicSetup() { // bpm is a constant deciding the tempo of the music. // when bpm is set to 60, one beat will last 1 second. 120 for half a second and so forth. const int bpm = 60; // Here we create a new orchestra using the output type WinmmOut which plays to the MIDI player in windows. _o = new Orchestra(new WinmmOut(0, bpm)); // Here we use the orchestra to create a new Instrument, in this case a choir. // We chose to use the chromatic scale from the Scale class, it is however unneccesary since it uses this scale by default. _instrument = _o.AddInstrument(InstrumentType.ChoirAahs, Scale.ChromaticScale, 0); _isPlaying = true; }
public void NoteTest(Tone tone, double duration, double starttime) { Note n = new Note(tone, duration); Orchestra o = new Orchestra(Substitute.For <IMidiOut>()); Instrument i = o.AddInstrument(InstrumentType.Banjo); IEnumerable <SingleBeat> list = n.GetChildren(i, starttime); List <SingleBeat> expected = new List <SingleBeat> { new SingleBeat(i.InstrumentType, (byte)(tone + 60), 64, starttime, starttime + duration), new SingleBeat(0, 0xff, 0xff, starttime + duration, starttime + duration) }; CollectionAssert.AreEqual(expected, list); }
public void WithBaseToneIndexerTest(double start, double def) { ChordVariety acd = new ChordVariety(1, 4, 7) { DefaultDuration = def }; Orchestra orc = new Orchestra(NSubstitute.Substitute.For <IMidiOut>()); Instrument ins = orc.AddInstrument(InstrumentType.Violin); List <SingleBeat> v = acd[Tone.CSharp].GetChildren(ins, start).ToList(); List <SingleBeat> comp = new List <SingleBeat> { new SingleBeat(InstrumentType.Violin, 61, 64, start, start + acd.DefaultDuration), new SingleBeat(InstrumentType.Violin, 64, 64, start, start + acd.DefaultDuration), new SingleBeat(InstrumentType.Violin, 67, 64, start, start + acd.DefaultDuration) }; CollectionAssert.AreEqual(comp, v); }
static void Main(string[] args) { #region Orchestra const int midiDeviceId = 0; //Most computers will only have this one. const int beatsPerSecond = 60; //Tempo of the music. 60 beats per second 1 one beat equals 1 second. IMidiOut output = new WinmmOut(midiDeviceId, beatsPerSecond); Orchestra orchestra = new Orchestra(output); Instrument piano = orchestra.AddInstrument(InstrumentType.BrightAcousticPiano); #endregion #region SingleSound //Play a single sound piano.Play(Tone.C, 1); orchestra.WaitForFinished(); #endregion #region MusicObjects MusicObject longF = new Note(Tone.F, 1); MusicObject shortF = new Note(Tone.F, 0.5); MusicObject longA = new Note(Tone.A, 1); MusicObject shortA = new Note(Tone.A, 0.5); MusicObject longG = new Note(Tone.G, 1); MusicObject shortG = new Note(Tone.G, 0.5); Console.WriteLine("Press enter to play a single sound"); Console.ReadLine(); //We can play any of those on an instrument if we wish piano.Play(shortG); orchestra.WaitForFinished(); #endregion #region LargeMusicObject //Create 2 smaller MusicObjects made out of the base pieces MusicObject sequence1 = new SequentialMusicList(longF, shortA, longG, shortA); MusicObject sequence2 = new SequentialMusicList(shortA, shortA, shortA, longA, shortF); //Now create a bigger MusicObject made of those 2 smaller ones and one new SequentialMusicList bigMusicObject = new SequentialMusicList(sequence1, sequence1, sequence2, new Note(Tone.D, 2)); //We can play this too //We can play any of those on an instrument if we wish Console.WriteLine("Press enter to play a longer sequence of sound"); Console.ReadLine(); piano.Play(bigMusicObject); orchestra.WaitForFinished(); #endregion #region Transformation //Make the 1st object a little lower on the scale, using a transform int[] offsets = { 0, -3, -3, -2 }; bigMusicObject[1] = bigMusicObject[1].Select <Note>((x, y) => x.OffsetBy(Scale.MajorScale, offsets[y])); //Play our final piece. Console.WriteLine("Press enter to play \"Drømte mig en drøm i nat\", "); Console.ReadLine(); piano.Play(bigMusicObject); orchestra.WaitForFinished(); //You have just heard https://en.wikipedia.org/wiki/Dr%C3%B8mde_mik_en_dr%C3%B8m_i_nat #endregion #region OtherInstrument //Create a flute Instrument flute = orchestra.AddInstrument(InstrumentType.Flute); Console.WriteLine("Press enter to play \"Drømte mig en drøm i nat\" on a flute"); Console.ReadLine(); flute.Play(bigMusicObject); orchestra.WaitForFinished(); #endregion #region TransformToChords //Using Select<>() it's also possible to change the type of a MusicObject. ChordVariety minor = ChordVariety.Minor; MusicObject asChords = bigMusicObject.Select <Note>(n => minor.WithBaseTone(n.Keystroke.Tone, n.Pause.Duration)); Console.WriteLine("Press enter to play \"Drømte mig en drøm i nat\" as minor."); Console.ReadLine(); piano.Play(asChords); orchestra.WaitForFinished(); #endregion }
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(); }