Example #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();        */
        }
Example #2
0
        /// <summary>
        /// Initializes the song with some required default values.
        /// </summary>
        /// <returns></returns>
        private void CreateDefaultScore()
        {
            _score = new Score();
            _score.Tempo = 120;
            _score.TempoLabel = "";

            _track = new Track();
            _track.PlaybackInfo.Program = 25;
            _track.PlaybackInfo.PrimaryChannel = TrackChannels[0];
            _track.PlaybackInfo.SecondaryChannel = TrackChannels[1];
            _track.Tuning = Tuning.GetDefaultTuningFor(6).Tunings;

            _score.AddTrack(_track);
        }
Example #3
0
        public Score JsObjectToScore(Score score)
        {
            var score2 = new Score();

            Score.CopyTo(score, score2);

            #region MasterBars

            for (var i = 0; i < score.MasterBars.Count; i++)
            {
                var masterBar  = score.MasterBars[i];
                var masterBar2 = new MasterBar();
                MasterBar.CopyTo(masterBar, masterBar2);
                if (masterBar.TempoAutomation != null)
                {
                    masterBar2.TempoAutomation = new Automation();
                    Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation);
                }
                if (masterBar.VolumeAutomation != null)
                {
                    masterBar2.VolumeAutomation = new Automation();
                    Automation.CopyTo(masterBar.VolumeAutomation, masterBar2.VolumeAutomation);
                }
                if (masterBar.Section != null)
                {
                    masterBar2.Section = new Section();
                    Section.CopyTo(masterBar.Section, masterBar2.Section);
                }
                score2.AddMasterBar(masterBar2);
            }

            #endregion

            #region Tracks

            for (int t = 0; t < score.Tracks.Count; t++)
            {
                var track  = score.Tracks[t];
                var track2 = new Track(track.Staves.Count);
                Track.CopyTo(track, track2);
                score2.AddTrack(track2);

                PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo);

                foreach (var key in track.Chords.Keys)
                {
                    var chord  = track.Chords[key];
                    var chord2 = new Chord();
                    Chord.CopyTo(chord, chord2);
                    track2.Chords[key] = chord2;
                }

                #region Staves

                for (var s = 0; s < track.Staves.Count; s++)
                {
                    var staff = track.Staves[s];
                    #region Bars

                    for (int b = 0; b < staff.Bars.Count; b++)
                    {
                        var bar  = staff.Bars[b];
                        var bar2 = new Bar();
                        Bar.CopyTo(bar, bar2);
                        track2.AddBarToStaff(s, bar2);

                        #region Voices

                        for (int v = 0; v < bar.Voices.Count; v++)
                        {
                            var voice  = bar.Voices[v];
                            var voice2 = new Voice();
                            Voice.CopyTo(voice, voice2);
                            bar2.AddVoice(voice2);

                            #region Beats

                            for (int bb = 0; bb < voice.Beats.Count; bb++)
                            {
                                var beat  = voice.Beats[bb];
                                var beat2 = new Beat();
                                Beat.CopyTo(beat, beat2);
                                voice2.AddBeat(beat2);

                                for (int a = 0; a < beat.Automations.Count; a++)
                                {
                                    var automation = new Automation();
                                    Automation.CopyTo(beat.Automations[a], automation);
                                    beat2.Automations.Add(automation);
                                }

                                for (int i = 0; i < beat.WhammyBarPoints.Count; i++)
                                {
                                    var point = new BendPoint();
                                    BendPoint.CopyTo(beat.WhammyBarPoints[i], point);
                                    beat2.WhammyBarPoints.Add(point);
                                }

                                #region Notes

                                for (int n = 0; n < beat.Notes.Count; n++)
                                {
                                    var note  = beat.Notes[n];
                                    var note2 = new Note();
                                    Note.CopyTo(note, note2);
                                    beat2.AddNote(note2);

                                    for (int i = 0; i < note.BendPoints.Count; i++)
                                    {
                                        var point = new BendPoint();
                                        BendPoint.CopyTo(note.BendPoints[i], point);
                                        note2.AddBendPoint(point);
                                    }
                                }

                                #endregion
                            }

                            #endregion
                        }

                        #endregion
                    }

                    #endregion
                }
                #endregion
            }

            #endregion

            score2.Finish();
            return(score2);
        }
Example #4
0
        public Score JsObjectToScore(Score score)
        {
            var score2 = new Score();
            Score.CopyTo(score, score2);

            #region MasterBars

            for (var i = 0;i < score.MasterBars.Count; i++)
            {
                var masterBar = score.MasterBars[i];
                var masterBar2 = new MasterBar();
                MasterBar.CopyTo(masterBar, masterBar2);
                if (masterBar.TempoAutomation != null)
                {
                    masterBar2.TempoAutomation = new Automation();
                    Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation);
                }
                if (masterBar.VolumeAutomation != null)
                {
                    masterBar2.VolumeAutomation = new Automation();
                    Automation.CopyTo(masterBar.VolumeAutomation, masterBar2.VolumeAutomation);
                }
                if (masterBar.Section != null)
                {
                    masterBar2.Section = new Section();
                    Section.CopyTo(masterBar.Section, masterBar2.Section);
                }
                score2.AddMasterBar(masterBar2);
            }

            #endregion

            #region Tracks

            for (int t = 0; t < score.Tracks.Count; t++)
            {
                var track = score.Tracks[t];
                var track2 = new Track();
                Track.CopyTo(track, track2);
                score2.AddTrack(track2);

                PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo);

                foreach (var key in track.Chords.Keys)
                {
                    var chord = track.Chords[key];
                    var chord2 = new Chord();
                    Chord.CopyTo(chord, chord2);
                    track2.Chords[key] = chord2;
                }

                #region Bars

                for (int b = 0; b < track.Bars.Count; b++)
                {
                    var bar = track.Bars[b];
                    var bar2 = new Bar();
                    Bar.CopyTo(bar, bar2);
                    track2.AddBar(bar2);

                    #region Voices

                    for (int v = 0; v < bar.Voices.Count; v++)
                    {
                        var voice = bar.Voices[v];
                        var voice2 = new Voice();
                        Voice.CopyTo(voice, voice2);
                        bar2.AddVoice(voice2);

                        #region Beats

                        for (int bb = 0; bb < voice.Beats.Count; bb++)
                        {
                            var beat = voice.Beats[bb];
                            var beat2 = new Beat();
                            Beat.CopyTo(beat, beat2);
                            voice2.AddBeat(beat2);

                            for (int a = 0; a < beat.Automations.Count; a++)
                            {
                                var automation = new Automation();
                                Automation.CopyTo(beat.Automations[a], automation);
                                beat2.Automations.Add(automation);
                            }
                            
                            for (int i = 0; i < beat.WhammyBarPoints.Count; i++)
                            {
                                var point = new BendPoint();
                                BendPoint.CopyTo(beat.WhammyBarPoints[i], point);
                                beat2.WhammyBarPoints.Add(point);
                            }
                            
                            #region Notes

                            for (int n = 0; n < beat.Notes.Count; n++)
                            {
                                var note = beat.Notes[n];
                                var note2 = new Note();
                                Note.CopyTo(note, note2);
                                beat2.AddNote(note2);

                                for (int i = 0; i < note.BendPoints.Count; i++)
                                {
                                    var point = new BendPoint();
                                    BendPoint.CopyTo(note.BendPoints[i], point);
                                    note2.AddBendPoint(point);
                                }
                            }

                            #endregion
                        }

                        #endregion
                    }

                    #endregion
                }
                
                #endregion
            }

            #endregion

            score2.Finish();
            return score2;
        }
        private static Score CreateSong(Song2014 song, IEnumerable<SongNoteChordWrapper> allSounds)
        {
            var score = new Score();
            score.Album = song.AlbumName;
            score.Artist = song.ArtistName;
            //score.copyright
            //score.instructions
            //score.music
            score.Notices = "Created by RockSmith Tab Explorer";
            //_score.subTitle
            //_score.tab
            score.Tempo = (int)song.AverageTempo;
            score.TempoLabel = "avg. bpm";
            score.Title = song.Title + " (" + song.Arrangement + ")";
            //_score.words

            bool isBass = song.Arrangement.ToLower() == "bass";

            var track = new Track();
            track.Name = song.Arrangement;
            track.Index = 1;
            int capo = track.Capo;
            track.TuningName = GetTuningName(song.Tuning, isBass, capo);
            track.ShortName = song.Arrangement;

            // Add string tunings in reverse order
            var tuning = new int[(isBass ? 4 : 6)];
            for (Byte s = 0; s < tuning.Length; s++)
            {
                tuning[tuning.Length - 1 - s] = Sng2014FileWriter.GetMidiNote(song.Tuning.ToShortArray(), s, 0, isBass, capo);
            }
            track.Tuning.AddRange(tuning);

            score.AddTrack(track);

            foreach (var chordTemplate in song.ChordTemplates.Where(ct=>ct.ChordId!=null))
            {
                var chord = new global::AlphaTab.Model.Chord();
                track.Chords[chordTemplate.ChordId.ToString()] = chord;

                chord.Name = chordTemplate.ChordName;
                chord.Strings.Add(chordTemplate.Fret0);
                chord.Strings.Add(chordTemplate.Fret1);
                chord.Strings.Add(chordTemplate.Fret2);
                chord.Strings.Add(chordTemplate.Fret3);
                chord.Strings.Add(chordTemplate.Fret4);
                chord.Strings.Add(chordTemplate.Fret5);
            }

            List<eBeatWrapper> ebeatMeasures = new List<eBeatWrapper>();
            eBeatWrapper currentMeasureBeat = null;
            foreach (var srcBeat in song.Ebeats)
            {
                if (srcBeat.Measure > 0)
                {
                    currentMeasureBeat = new eBeatWrapper() { MeasureStartBeat = srcBeat, MeasureSubBeats = new List<SongEbeat>() };
                    ebeatMeasures.Add(currentMeasureBeat);
                }
                else
                {
                    if (currentMeasureBeat == null)
                        System.Diagnostics.Debug.WriteLine("Invalid ebeats in source file. Sub measure is before first measure!?");
                    else
                        currentMeasureBeat.MeasureSubBeats.Add(srcBeat);
                }
            }

            var notesStack = new Stack<SongNoteChordWrapper>(allSounds.OrderByDescending(x => x.Time));
            var currentNote = notesStack.Pop();
            var nextNote = notesStack.Pop();

            int prevMeasureId = 0;
            int i = 1;
            float prevMeasureDuration=0;
            foreach (var measure in ebeatMeasures)
            {
                var nextmeasure = i < ebeatMeasures.Count ? ebeatMeasures[i] : null;
                if (measure.MeasureStartBeat.Measure > prevMeasureId)
                {
                    var measureDuration = nextmeasure !=null ? nextmeasure.MeasureStartBeat.Time - measure.MeasureStartBeat.Time : prevMeasureDuration;
                    AddMasterBarToScore(score, measure.MeasureStartBeat.Time.ToString("n2"), measure);
                    var voice = AddBarAndVoiceToTrack(track, isBass ? Clef.F4 : Clef.G2);

                    bool firstNoteInBar = true;
                    while (currentNote != null && (nextmeasure == null || currentNote.Time < nextmeasure.MeasureStartBeat.Time))
                    {
                        if (currentNote.IsNote() && currentNote.AsNote().Bend != 0)
                            System.Diagnostics.Debug.WriteLine("Bent detected. Bend value: {0}. Measure: {1}", currentNote.AsNote().Bend, measure.MeasureStartBeat.Measure);
                        Duration duration = Duration.Quarter;

                        if (firstNoteInBar && currentNote.Time > measure.MeasureStartBeat.Time)
                        {
                            var leadingSilenceTicks = Get64thsFromDuration(measure.MeasureStartBeat.Time, currentNote.Time, measureDuration);
                            while (leadingSilenceTicks >= 1)
                            {
                                if (leadingSilenceTicks >= 32)
                                {
                                    AddBeatAndSilenceToVoice(voice, Duration.Half);
                                    leadingSilenceTicks -= 32;
                                }
                                else if (leadingSilenceTicks >= 16)
                                {
                                    AddBeatAndSilenceToVoice(voice, Duration.Quarter);
                                    leadingSilenceTicks -= 16;
                                }
                                else if (leadingSilenceTicks >= 8)
                                {
                                    AddBeatAndSilenceToVoice(voice, Duration.Eighth);
                                    leadingSilenceTicks -= 8;
                                }
                                else if (leadingSilenceTicks >= 4)
                                {
                                    AddBeatAndSilenceToVoice(voice, Duration.Sixteenth);
                                    leadingSilenceTicks -= 4;
                                }
                                else if (leadingSilenceTicks >= 2)
                                {
                                    AddBeatAndSilenceToVoice(voice, Duration.ThirtySecond);
                                    leadingSilenceTicks -= 2;
                                }
                                else if (leadingSilenceTicks >= 1)
                                {
                                    AddBeatAndSilenceToVoice(voice, Duration.SixtyFourth);
                                    leadingSilenceTicks -= 1;
                                }
                            }
                        }

                        Single durationTime = 0;
                        if (nextNote != null)
                        {
                            duration = GetBeatDuration(currentNote.Time, nextNote.Time, measureDuration);
                            durationTime = nextNote.Time - currentNote.Time;
                        }
                        else
                        {
                            durationTime = measureDuration;
                        }

                        if (currentNote.IsNote())
                            AddBeatAndNoteToVoice(voice, currentNote.AsNote(), duration, durationTime);
                        else
                            AddBeatWithChordToVoice(voice, currentNote.AsChord(), duration, durationTime);

                        currentNote = nextNote;
                        if (notesStack.Any())
                            nextNote = notesStack.Pop();
                        else
                            nextNote = null;
                        firstNoteInBar = false;
                    }

                    prevMeasureId = measure.MeasureStartBeat.Measure;
                    prevMeasureDuration = measureDuration;
                }
                i++;
            }
            return score;
        }
Example #6
0
        /// <summary>
        /// Converts the given JavaScript object into a score object.
        /// </summary>
        /// <param name="jsObject">The javascript object created via <see cref="ScoreToJsObject"/></param>
        /// <param name="settings">The settings to use during conversion.</param>
        /// <returns>The converted score object.</returns>
        public static Score JsObjectToScore(object jsObject, Settings settings = null)
        {
            Score score  = jsObject.As <Score>();
            var   score2 = new Score();

            Score.CopyTo(score, score2);
            RenderStylesheet.CopyTo(score.Stylesheet, score2.Stylesheet);

            #region MasterBars

            for (var i = 0; i < score.MasterBars.Count; i++)
            {
                var masterBar  = score.MasterBars[i];
                var masterBar2 = new MasterBar();
                MasterBar.CopyTo(masterBar, masterBar2);
                if (masterBar.TempoAutomation != null)
                {
                    masterBar2.TempoAutomation = new Automation();
                    Automation.CopyTo(masterBar.TempoAutomation, masterBar2.TempoAutomation);
                }
                if (masterBar.Section != null)
                {
                    masterBar2.Section = new Section();
                    Section.CopyTo(masterBar.Section, masterBar2.Section);
                }

                foreach (var offset in masterBar.Fermata)
                {
                    var fermata  = masterBar.Fermata[offset];
                    var fermata2 = new Fermata();
                    Fermata.CopyTo(fermata, fermata2);
                    masterBar2.AddFermata(offset, fermata2);
                }


                score2.AddMasterBar(masterBar2);
            }

            #endregion

            #region Tracks

            for (int t = 0; t < score.Tracks.Count; t++)
            {
                var track  = score.Tracks[t];
                var track2 = new Track(track.Staves.Count);
                Track.CopyTo(track, track2);
                score2.AddTrack(track2);

                PlaybackInformation.CopyTo(track.PlaybackInfo, track2.PlaybackInfo);


                #region Staves

                for (var s = 0; s < track.Staves.Count; s++)
                {
                    var staff  = track.Staves[s];
                    var staff2 = track2.Staves[s];
                    Staff.CopyTo(staff, staff2);


                    foreach (var key in staff.Chords)
                    {
                        var chord  = staff.Chords[key];
                        var chord2 = new Chord();
                        Chord.CopyTo(chord, chord2);
                        staff2.Chords[key] = chord2;
                    }
                    #region Bars

                    for (int b = 0; b < staff.Bars.Count; b++)
                    {
                        var bar  = staff.Bars[b];
                        var bar2 = new Bar();
                        Bar.CopyTo(bar, bar2);
                        staff2.AddBar(bar2);

                        #region Voices

                        for (int v = 0; v < bar.Voices.Count; v++)
                        {
                            var voice  = bar.Voices[v];
                            var voice2 = new Voice();
                            Voice.CopyTo(voice, voice2);
                            bar2.AddVoice(voice2);

                            #region Beats

                            for (int bb = 0; bb < voice.Beats.Count; bb++)
                            {
                                var beat  = voice.Beats[bb];
                                var beat2 = new Beat();
                                Beat.CopyTo(beat, beat2);
                                voice2.AddBeat(beat2);

                                for (int a = 0; a < beat.Automations.Count; a++)
                                {
                                    var automation = new Automation();
                                    Automation.CopyTo(beat.Automations[a], automation);
                                    beat2.Automations.Add(automation);
                                }

                                for (int i = 0; i < beat.WhammyBarPoints.Count; i++)
                                {
                                    var point = new BendPoint();
                                    BendPoint.CopyTo(beat.WhammyBarPoints[i], point);
                                    beat2.AddWhammyBarPoint(point);
                                }

                                #region Notes

                                for (int n = 0; n < beat.Notes.Count; n++)
                                {
                                    var note  = beat.Notes[n];
                                    var note2 = new Note();
                                    Note.CopyTo(note, note2);
                                    beat2.AddNote(note2);

                                    for (int i = 0; i < note.BendPoints.Count; i++)
                                    {
                                        var point = new BendPoint();
                                        BendPoint.CopyTo(note.BendPoints[i], point);
                                        note2.AddBendPoint(point);
                                    }
                                }

                                #endregion
                            }

                            #endregion
                        }

                        #endregion
                    }

                    #endregion
                }
                #endregion
            }

            #endregion

            score2.Finish(settings);
            return(score2);
        }
Example #7
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;
        }