public void SequentialGetChildrenTest2()
        {
            MusicObject[] testObjects = new MusicObject[5];
            testObjects[0] = new Keystroke(Tone.A, 2);
            testObjects[1] = new Pause(1);
            testObjects[2] = new ChordVariety(1, 4, 7).WithBaseTone(Tone.E, 2);
            testObjects[3] = new Pause(1);
            testObjects[4] = new Keystroke(Tone.D, 2);
            List <SingleBeat> sSBList = new List <SingleBeat>();

            SequentialMusicList sTestList = new SequentialMusicList(testObjects);
            IOrchestra          testOrc   = Substitute.For <IOrchestra>();
            Instrument          i         = new Instrument(testOrc, InstrumentType.AcousticBass, new Scale());

            sSBList.AddRange(sTestList.GetChildren(i, 1));

            int    testInt    = 0;
            double testDouble = 0;

            foreach (SingleBeat sb in sSBList)
            {
                if ((sb.ToneStartTime > testDouble))
                {
                    testInt++;
                }
                testDouble = sb.ToneStartTime;
            }

            Assert.IsTrue(testInt == 3);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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
        }