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);
        }
        public void SequentialGetChildrenTest()
        {
            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> 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));


            double testDouble = 0;

            foreach (SingleBeat sb in sSBList)
            {
                if (!(sb.ToneStartTime >= testDouble))
                {
                    Assert.Fail();
                }
                testDouble = sb.ToneStartTime;
            }
        }
Ejemplo n.º 3
0
        // This method plays different sounds at different times based on the coordinates of all living cells in the game.
        // The x coordinates decides which tones are used.
        // The y-coordinates decides when sounds are played.
        private void PlayMidiMusic()
        {
            SequentialMusicList sMusic = new SequentialMusicList();
            int localInt;

            // This nested for-loop iterates over all cells in the game.
            for (int y = 0; y < _yValue; y++)
            {
                for (int x = 0; x < _xValue; x++)
                {
                    // This if statement checks whether a cell is still alive
                    if (Cells[x, y])
                    {
                        localInt = x < _xValue / 2 ? x : _xValue - x;
                        // This creates a new keystroke with an offset based on where in the grid the cell is, and adds it to the SequentailMusicList.
                        sMusic.Add(new Keystroke(Tone.C, 1).OffsetBy(_quintScale, localInt));
                    }
                }
                // We add a pause here to play sounds later if they have a greater y-coordinate.
                sMusic.Add(new Pause(1));
            }
            // This plays all the sounds in the list, as longs it contains any ,and as long as the instrument isn't null.
            if (sMusic.Count != 0)
            {
                _instrument?.Play(sMusic);
            }
        }
Ejemplo n.º 4
0
        static MusicObject bigMusicObject()
        {
            SequentialMusicList list1 = new SequentialMusicList(ListWithoutNull().Shuffle(423)),
                                list2 = new SequentialMusicList(list1, new SequentialMusicList(ListWithoutNull().Shuffle(2)));


            return(new ParallelMusicCollection(list1, list2));
        }
        public void SequentialMusicCollectionTest()
        {
            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);

            SequentialMusicList sTest = new SequentialMusicList(testObjects);

            Assert.IsTrue(sTest.Contains(testObjects[0]) && sTest.Contains(testObjects[1]) && sTest.Contains(testObjects[2]) && sTest.Contains(testObjects[3]) && sTest.Contains(testObjects[4]));
        }
Ejemplo n.º 6
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
        }
Ejemplo n.º 7
0
        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();
        }