Exemple #1
0
        static void Main(string[] args)
        {
            var midiModel = new SanfordMidiMarkov(2);

            midiModel.EnsureUniqueWalk = true;

            var files = Directory.GetFiles("music");

            int division = 0;

            foreach (var file in files)
            {
                var sequence = new Sequence(file);
                division = sequence.Division;
                midiModel.Learn(sequence);
            }
            var sequenceNew = new Sequence(division);

            Console.ReadLine();
            //var tracks = midiModel.Walk();
            //foreach (var track in tracks)
            //{
            //    sequenceNew.Add(track);
            //}
            var track = midiModel.Walk().First();

            sequenceNew.Add(track);

            sequenceNew.Save("dubstep2.mid");
            Console.WriteLine("done");
            Console.ReadLine();
        }
Exemple #2
0
        public void MidiGen()
        {
            try
            {
                string midiFile = DirGet.GetMidiPath();

                Sequence seq    = new Sequence(midiFile);
                Sequence seqNew = new Sequence(seq.Division);

                // Get a random track to learn from
                // Take more to produce output on multiple tracks.
                var ints = Enumerable.Range(0, seq.Count).OrderBy(a => Guid.NewGuid()).Take(1);
                foreach (int i in ints)
                {
                    Track             t     = seq[i];
                    SanfordMidiMarkov model = new SanfordMidiMarkov(2);
                    model.EnsureUniqueWalk = true;

                    // Learn the track
                    model.Learn(t);

                    // Walk the model
                    var result = model.Walk().FirstOrDefault();

                    // Add the result to the new sequence
                    seqNew.Add(result);
                }

                // Write a new midi file
                seqNew.Save(DirGet.GetPath() + "Generated\\Midi\\aaaaaaaa.mid");
            }
            catch (DirectoryNotFoundException dirEx)
            {
                // Let the user know that the directory did not exist.
                Console.WriteLine("Directory not found: " + dirEx.Message);
            }
        }