예제 #1
0
        static void ANNFFNAccomp()
        {
            Databank db = new Databank("lib");
            var cat = db.Load("Classical");

            Composition inputComp = cat.Compositions[6];
            MelodySequence inputSeq = inputComp.Tracks[0].GetMainSequence() as MelodySequence;

            AccompanimentGeneratorANNFF gen = new AccompanimentGeneratorANNFF(cat, PatchNames.Acoustic_Grand);
            //gen.Initialize();
            gen.SetSequence(inputSeq);
            gen.Train();

            var outMel = gen.Generate();

            MusicPlayer player = new MusicPlayer();

            Composition comp = new Composition();
            Track t = new Track(PatchNames.Orchestral_Strings, 6);
            t.AddSequence(outMel);
            comp.Add(t);
            comp.Add(inputComp.Tracks[0]);
            player.Play(comp);
            comp.WriteToMidi("ann_ff_accomp.mid");
        }
예제 #2
0
 static void WriteMelodyToFile(MelodySequence seq, string filename)
 {
     Composition comp = new Composition();
     Track track = new Track(PatchNames.Acoustic_Grand, 1);
     track.AddSequence(seq);
     comp.Add(track);
     comp.WriteToMidi(filename);
 }
예제 #3
0
        static void MarkovAccompTest()
        {
            Databank db = new Databank("lib");
            var cat = db.Load("Classical");

            Composition inputComp = cat.Compositions[6];
            MelodySequence inputSeq = inputComp.Tracks[0].GetMainSequence() as MelodySequence;

            AccompanyGeneratorMarkov gen = new AccompanyGeneratorMarkov(cat, PatchNames.Orchestral_Strings);

            var outMel = gen.Generate(inputSeq, 10);

            MusicPlayer player = new MusicPlayer();

            Composition comp = new Composition();
            Track t = new Track(gen.Instrument, 6);
            t.AddSequence(outMel);
            comp.Add(t);
            comp.Add(inputComp.Tracks[0]);
            player.Play(comp);
            comp.WriteToMidi("markov_model_accomp.mid");
        }
예제 #4
0
        static void InstrumentalTest()
        {
            Databank db = new Databank("lib");
            var cat = db.Load("Classical");

            InstrumentalGenerator gen = new InstrumentalGenerator(cat);
            gen.Initialize();
            var outMel = gen.GenerateInstrument(PatchNames.Acoustic_Grand, 40);

            MusicPlayer player = new MusicPlayer();
            player.Play(outMel);

            Composition comp = new Composition();
            Track t = new Track(PatchNames.Acoustic_Grand, 3);
            t.AddSequence(outMel);
            comp.Add(t);
            comp.WriteToMidi("instrumental_acousticgrand.mid");
        }
예제 #5
0
        static void GeneticTest()
        {
            Databank db = new Databank("lib");
            var cat = db.Load("Classical");

            MetricSimilarity cosine = MetricSimilarity.GenerateMetricSimilarityMulti(cat.Compositions, new IMetric[] { new ChromaticToneDistance(), new MelodicInterval(), new ChromaticToneDuration(), new RhythmicBigram() });
            GeneticGenerator gen = new GeneticGenerator(cosine, PatchNames.Orchestral_Strings, cat);
            gen.OnPercentage += (sender, percentage, fitness) => { Console.WriteLine("{0}: {1}", percentage, fitness); };
            gen.MaxGenerations = 1000;
            var outMel = gen.Generate();

            MusicPlayer player = new MusicPlayer();
            player.Play(outMel);

            Composition comp = new Composition();
            Track t = new Track(gen.Instrument, 3);
            t.AddSequence(outMel);
            comp.Add(t);
            comp.WriteToMidi("genetic_cosine_all.mid");
        }