Exemple #1
0
        private void beginGenerationButton_Click(object sender, EventArgs e)
        {
            try
            {
                var retriever  = new PianoNoteRetriever();
                var midiEvents = new InstrumentMidiEventProducer(this.files.Select(x => new Sequence(x)));
                IReadOnlyList <MidiEvent> midi = midiEvents.GetOrderedMessages(GeneralMidiInstrument.AcousticGrandPiano);

                Chord.AllowForComplexSimplification = this.checkBox1.Checked;
                var accords = Chord.RetrieveChords(midi, retriever);

                INGrams <Chord> grams = null;
                if (this.homogeneous)
                {
                    grams = HomogenousNGrams <Chord> .BuildNGrams((int)this.leftRangeNumericUpDown.Value, accords);
                }
                else
                {
                    grams = HeterogenousNGrams <Chord> .BuildNGrams((int)this.leftRangeNumericUpDown.Value, (int)this.rightRangeNumericUpDown.Value, accords);
                }

                NGramGraphMarkovChain <Chord> graph = new NGramGraphMarkovChain <Chord>(grams);
                this.Save(graph);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
        public INGrams <T> UpdateSentenceTextBox()
        {
            var chain = RetrieveChain();

            this.sentenceTextBox.Text = NGramHelper.ShowNGram(chain);

            return(HomogenousNGrams <T> .DirectBuiltUnsafe(chain, chain.First().N));
        }
        public DiscreteDataRetriever(List <Chord> chordsInOrder, int clusterSize = 2, int windowSize = 20)
        {
            chordsInOrder.NullCheck();
            chordsInOrder.Any().AssertTrue();

            this.Chords = chordsInOrder.AsReadOnly();

            this.WindowSize = windowSize;
            this.NGramSize  = clusterSize;

            this.HomogenousWindowingData = HomogenousNGrams <Chord> .BuildNGrams(this.NGramSize, this.Chords.ToList());

            this.badOkayGoodChords = Tuple.Create <List <NGram <Chord>[]>, List <NGram <Chord>[]>, List <NGram <Chord>[]> >(this.RetrieveBad(), this.RetrieveOkay(), this.RetrieveGood());
        }
        public override void FormLoad(object sender, EventArgs e)
        {
            PianoNoteRetriever retriever = new PianoNoteRetriever();

            var midiEvents = new InstrumentMidiEventProducer(
                Directory.EnumerateFiles(@"C:\Users\armen_000\Documents\Visual Studio 2013\Projects\Improvisation\Improvisation\bin\Debug\MusicSeperated\RayCharles").Select(x => new Sequence(x)));
            var midi    = midiEvents.GetOrderedMessages(GeneralMidiInstrument.AcousticGrandPiano);
            var accords = Chord.RetrieveChords(midi, retriever);

            //    var mahboyeminem = Chord.RetrieveChords(
            //      new InstrumentMidiEventProducer(Directory.EnumerateFiles("MusicSeperated\\Eminem").Select(x => new Sequence(x))).GetOrderedMessages(GeneralMidiInstrument.AcousticGrandPiano),
            //    retriever);


            var grams = HeterogenousNGrams <Chord> .BuildNGrams(3, 7, accords.ToList());

            this.MarkovGraph = new NGramGraphMarkovChain <Chord>(grams);

            this.wpfContainer.Child = GenerateWpfVisuals(GraphUIHelper.GenerateGraphUI <Chord>(new NGramGraphMarkovChain <Chord>(HomogenousNGrams <Chord> .DirectBuiltUnsafe(new NGram <Chord>().AsEnumerableObject(), 1))));

            this.ZoomControl.ZoomToFill();

            this.GraphArea.GenerateGraph(true);
            this.GraphArea.SetVerticesDrag(true, true);

            this.UpdateThemeListBox();
        }
        private List <NGram <Chord>[]> RetrieveGood()
        {
            var window = HomogenousNGrams <NGram <Chord> > .BuildNGrams(this.WindowSize, this.HomogenousWindowingData.ToList());

            return(window.Select(x => x.ToArray()).ToList());
        }
        private async void ShowMelodyDifference(NGram <Chord>[] nGram)
        {
            NGramGraphMarkovChain <Chord>      melodyGraph = new NGramGraphMarkovChain <Chord>(HomogenousNGrams <Chord> .DirectBuiltUnsafe(nGram, 1));
            NGramSemanticGraphDistance <Chord> a           = new Library.GraphOperations.NGramSemanticGraphDistance <Chord>();

            string text = a.Distance(
                melodyGraph,
                TemperaryVariables.Graph,
                (this.useSubGraphCheckBox.Checked) ?
                NGramGraphDistanceType.SubGraph :
                NGramGraphDistanceType.CompleteGraph
                ).ToString();

            this.graphDifferenceTextBox.Invoke((Action)(() => this.graphDifferenceTextBox.Text = text));
        }