Finish() public method

public Finish ( ) : void
return void
示例#1
0
        public void SetNotes(GeneticMIDI.Representation.Track track)
        {
            if (track.Length < 1)
                return;

            var mel = track.GetMelodySequence();

            //return;

            score = new Score();

            Track t = new Track();

            MasterBar mb = new MasterBar();
            score.AddMasterBar(mb);
            mb.KeySignature = 2;

            Bar b = new Bar();
            t.AddBar(b);
            score.AddTrack(t);

            Voice v = new Voice();
            b.AddVoice(v);

            t.Name = track.Instrument.ToString().Replace("_", " ");

            //t.IsPercussion = true;
            if(t.IsPercussion)
            {

                b.Clef = Clef.Neutral;
            }

            int i = 0;

            int qn_per_bar = 4;

            int durs = 0;
            int avg_octave = mel.CalculateAverageOctave();
            int dist4 = 4 - avg_octave;
            foreach (var n in mel.Notes)
            {
                Beat be = new Beat();
                be.Index = i++;

                GeneticMIDI.Representation.Durations dur;
                int remainder;

                n.GetClosestLowerDurationAndRemainder(out dur, out remainder);

                int dots = n.GetNumberOfDots();

                durs += n.Duration;

                /*        if(durs >= qn_per_bar * (int)GeneticMIDI.Representation.Durations.qn)
                        {
                            durs = 0;
                            b = new Bar();
                            t.AddBar(b);
                            v.Bar = b;
                            b.Finish();
                        }*/

                switch (((GeneticMIDI.Representation.Durations)n.Duration))
                {
                    case GeneticMIDI.Representation.Durations.bn:
                        be.Duration = AlphaTab.Model.Duration.Whole;
                        dots = 2;
                        break;
                    case GeneticMIDI.Representation.Durations.en:
                        be.Duration = AlphaTab.Model.Duration.Eighth;
                        break;
                    case GeneticMIDI.Representation.Durations.hn:
                        be.Duration = AlphaTab.Model.Duration.Half;
                        break;
                    case GeneticMIDI.Representation.Durations.qn:
                        be.Duration = AlphaTab.Model.Duration.Quarter;
                        break;
                    case GeneticMIDI.Representation.Durations.sn:
                        be.Duration = AlphaTab.Model.Duration.Sixteenth;
                        break;
                    case GeneticMIDI.Representation.Durations.tn:
                        be.Duration = AlphaTab.Model.Duration.ThirtySecond;
                        break;
                    case GeneticMIDI.Representation.Durations.wn:
                        be.Duration = AlphaTab.Model.Duration.Whole;
                        break;
                    default:
                        break;
                }
                be.Dots = dots;

                Note note = new Note();

                if (!n.IsRest())
                {
                    note.Tone = n.NotePitch;
                    note.Octave = n.Octave + dist4;

                    be.AddNote(note);
                    be.IsEmpty = false;
                }

                if (n.IsRest() && n.Duration < 2)
                {

                }
                else
                    v.AddBeat(be);

                be.RefreshNotes();

            }

            v.Bar = b;

            v.Finish();

            b.Finish();

            t.Finish();

            score.Finish();

            //TablatureControl

            _renderer.Render(t);
            return;

            /*TablatureControl.Track = t;
            TablatureControl.InvalidateVisual();
            TablatureControl.InvalidateTrack();        */
        }
示例#2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var comp = GeneticMIDI.Representation.Composition.LoadFromMIDI(@"C:\Users\1gn1t0r\Documents\git\GeneticMIDI\GeneticMIDI\bin\Debug\test\harry.mid");
            var mel = comp.Tracks[0].GetMainSequence() as GeneticMIDI.Representation.MelodySequence;
            Score score = new Score();
            Track t = new Track();

            var pc = t.IsPercussion;

            MasterBar mb = new MasterBar();
            score.AddMasterBar(mb);
            mb.KeySignature = 2;

            Bar b = new Bar();
            t.AddBar(b);
            score.AddTrack(t);

            Voice v = new Voice();
            b.AddVoice(v);

            int i = 0;

            int qn_per_bar = 4;

            int durs = 0;
            int avg_octave = mel.CalculateAverageOctave();
            int dist4 = 4 - avg_octave;
            foreach(var n in mel.Notes)
            {
                Beat be = new Beat();
                be.Index = i++;

                GeneticMIDI.Representation.Durations dur;
                int remainder;

                n.GetClosestLowerDurationAndRemainder(out dur, out remainder);

                int dots = n.GetNumberOfDots();

                durs += n.Duration;

            /*        if(durs >= qn_per_bar * (int)GeneticMIDI.Representation.Durations.qn)
                {
                    durs = 0;
                    b = new Bar();
                    t.AddBar(b);
                    v.Bar = b;
                    b.Finish();
                }*/

                switch (((GeneticMIDI.Representation.Durations)n.Duration))
                {
                    case GeneticMIDI.Representation.Durations.bn:
                        be.Duration = Model.Duration.Whole;
                        dots = 2;
                        break;
                    case GeneticMIDI.Representation.Durations.en:
                        be.Duration = Model.Duration.Eighth;
                        break;
                    case GeneticMIDI.Representation.Durations.hn:
                        be.Duration = Model.Duration.Half;
                        break;
                    case GeneticMIDI.Representation.Durations.qn:
                        be.Duration = Model.Duration.Quarter;
                        break;
                    case GeneticMIDI.Representation.Durations.sn:
                        be.Duration = Model.Duration.Sixteenth;
                        break;
                    case GeneticMIDI.Representation.Durations.tn:
                        be.Duration = Model.Duration.ThirtySecond;
                        break;
                    case GeneticMIDI.Representation.Durations.wn:
                        be.Duration = Model.Duration.Whole;
                        break;
                    default:
                        break;
                }
                be.Dots = dots;

                Note note = new Note();
                if (!n.IsRest())
                {
                    note.Tone = n.NotePitch;
                    note.Octave = n.Octave + dist4;
                    be.AddNote(note);
                    be.IsEmpty = false;

                }

                if(n.IsRest() && n.Duration < 2)
                {

                }
                else
                    v.AddBeat(be);

                be.RefreshNotes();

            }

            v.Bar = b;

            v.Finish();

            b.Finish();

            t.Finish();

            score.Finish();

            viewModel.Score = score;
            viewModel.CurrentTrackIndex = 0;
        }