A voice represents a group of beats that can be played during a bar.
 private static Voice AddBarAndVoiceToTrack(Track track, Clef clef)
 {
     var bar = new Bar();
     bar.Clef = clef;
     track.AddBar(bar);
     var voice = new Voice();
     bar.AddVoice(voice);
     return voice;
 }
 private void CreateVoiceGlyphs(Voice voice)
 {
     for (int i = 0, j = voice.Beats.Count; i < j; i++)
     {
         var b = voice.Beats[i];
         // we create empty glyphs as alignment references and to get the 
         // effect bar sized
         var container = new BeatContainerGlyph(b);
         container.PreNotes = new BeatGlyphBase();
         container.OnNotes = new BeatGlyphBase();
         container.PostNotes = new BeatGlyphBase();
         AddBeatGlyph(container);
     }
 }
Exemplo n.º 3
0
 private void GenerateVoice(Voice voice, int startMove)
 {
     for (int i = 0, j = voice.Beats.Count; i < j; i++)
     {
         GenerateBeat(voice.Beats[i], startMove);
     }
 }
Exemplo n.º 4
0
        public void ReadVoice(Track track, Bar bar)
        {
            var beatCount = ReadInt32();
            if (beatCount == 0)
            {
                return;
            }

            var newVoice = new Voice();
            bar.AddVoice(newVoice);

            for (int i = 0; i < beatCount; i++)
            {
                ReadBeat(track, bar, newVoice);
            }
        }
Exemplo n.º 5
0
 public void AddVoice(Voice voice)
 {
     voice.Bar = this;
     voice.Index = Voices.Count;
     Voices.Add(voice);
 }
Exemplo n.º 6
0
        private void Bar()
        {
            var master = new MasterBar();
            _score.AddMasterBar(master);

            var bar = new Bar();
            _track.AddBar(bar);

            if (master.Index > 0)
            {
                master.KeySignature = master.PreviousMasterBar.KeySignature;
                master.TimeSignatureDenominator = master.PreviousMasterBar.TimeSignatureDenominator;
                master.TimeSignatureNumerator = master.PreviousMasterBar.TimeSignatureNumerator;
                bar.Clef = bar.PreviousBar.Clef;
            }
            BarMeta(bar);

            var voice = new Voice();
            bar.AddVoice(voice);

            while (_sy != AlphaTexSymbols.Pipe && _sy != AlphaTexSymbols.Eof)
            {
                Beat(voice);
            }

            if (voice.Beats.Count == 0)
            {
                var emptyBeat = new Beat();
                emptyBeat.IsEmpty = true;
                voice.AddBeat(emptyBeat);
            }
        }
Exemplo n.º 7
0
 private void CreateVoiceGlyphs(Voice v)
 {
     for (int i = 0, j = v.Beats.Count; i < j; i++)
     {
         var b = v.Beats[i];
         var container = new ScoreBeatContainerGlyph(b);
         container.PreNotes = new ScoreBeatPreNotesGlyph();
         container.OnNotes = new ScoreBeatGlyph();
         ((ScoreBeatGlyph)container.OnNotes).BeamingHelper = _helpers.BeamHelperLookup[v.Index][b.Index];
         container.PostNotes = new ScoreBeatPostNotesGlyph();
         AddBeatGlyph(container);
     }
 }
Exemplo n.º 8
0
 private void CreateVoiceGlyphs(Voice v)
 {
     for (int i = 0, j = v.Beats.Count; i < j; i++)
     {
         var b = v.Beats[i];
         var container = new ScoreBeatContainerGlyph(b, GetOrCreateVoiceContainer(v));
         container.PreNotes = new ScoreBeatPreNotesGlyph();
         container.OnNotes = new ScoreBeatGlyph();
         AddBeatGlyph(container);
     }
 }
Exemplo n.º 9
0
 private void GenerateVoice(Voice voice, int barStartTick)
 {
     for (int i = 0, j = voice.Beats.Count; i < j; i++)
     {
         GenerateBeat(voice.Beats[i], barStartTick);
     }
 }
Exemplo n.º 10
0
        public void ReadNote(Track track, Bar bar, Voice voice, Beat beat, int stringIndex)
        {
            var newNote = new Note();
            newNote.String = track.Tuning.Length - stringIndex;

            var flags = Data.ReadByte();
            if ((flags & 0x02) != 0)
            {
                newNote.Accentuated = AccentuationType.Heavy;
            }
            else if ((flags & 0x40) != 0)
            {
                newNote.Accentuated = AccentuationType.Normal;
            }

            newNote.IsGhost = ((flags & 0x04) != 0);
            if ((flags & 0x20) != 0)
            {
                var noteType = Data.ReadByte();
                if (noteType == 3)
                {
                    newNote.IsDead = true;
                }
                else if (noteType == 2)
                {
                    newNote.IsTieDestination = true;
                }
            }

            if ((flags & 0x01) != 0 && _versionNumber < 500)
            {
                Data.ReadByte(); // duration
                Data.ReadByte();  // tuplet
            }

            if ((flags & 0x10) != 0)
            {
                var dynamicNumber = Data.ReadSignedByte();
                newNote.Dynamic = ToDynamicValue(dynamicNumber);
                beat.Dynamic = newNote.Dynamic;
            }

            if ((flags & 0x20) != 0)
            {
                newNote.Fret = Data.ReadSignedByte();
            }

            if ((flags & 0x80) != 0)
            {
                newNote.LeftHandFinger = (Fingers)Data.ReadSignedByte();
                newNote.RightHandFinger = (Fingers)Data.ReadSignedByte();
                newNote.IsFingering = true;
            }

            if (_versionNumber >= 500)
            {
                if ((flags & 0x01) != 0)
                {
                    newNote.DurationPercent = ReadDouble();
                }
                var flags2 = Data.ReadByte();
                newNote.AccidentalMode = (flags2 & 0x02) != 0
                    ? NoteAccidentalMode.SwapAccidentals
                    : NoteAccidentalMode.Default;
            }

            beat.AddNote(newNote);
            if ((flags & 0x08) != 0)
            {
                ReadNoteEffects(track, voice, beat, newNote);
            }
        }
Exemplo n.º 11
0
 protected VoiceContainerGlyph GetOrCreateVoiceContainer(Voice voice)
 {
     return _voiceContainers[voice.Index];
 }
Exemplo n.º 12
0
 public VoiceContainerGlyph(float x, float y, Voice voice)
     : base(x, y)
 {
     Voice = voice;
     BeatGlyphs = new FastList<BeatContainerGlyph>();
 }
Exemplo n.º 13
0
 private void Voice(Voice voice)
 {
     for (int i = 0; i < voice.Beats.Count; i++)
     {
         Beat(voice.Beats[i]);
     }
 }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
        private void CreateVoiceGlyphs(Voice v)
        {
            for (int i = 0, j = v.Beats.Count; i < j; i++)
            {
                var b = v.Beats[i];
                // we create empty glyphs as alignment references and to get the
                // effect bar sized
                var container = new BeatContainerGlyph(b);
                container.PreNotes = new BeatGlyphBase();
                container.OnNotes = new BeatGlyphBase();
                container.PostNotes = new BeatGlyphBase();
                AddBeatGlyph(container);

                if (_info.ShouldCreateGlyph(this, b))
                {
                    CreateOrResizeGlyph(_info.SizingMode, b);
                }

                _lastBeat = b;
            }
        }
Exemplo n.º 16
0
        public void ReadBeat(Track track, Bar bar, Voice voice)
        {
            var newBeat = new Beat();
            var flags = Data.ReadByte();

            if ((flags & 0x01) != 0)
            {
                newBeat.Dots = 1;
            }

            if ((flags & 0x40) != 0)
            {
                var type = Data.ReadByte();
                newBeat.IsEmpty = (type & 0x02) == 0;
            }
            voice.AddBeat(newBeat);

            var duration = Data.ReadSignedByte();
            switch (duration)
            {
                case -2:
                    newBeat.Duration = Duration.Whole;
                    break;
                case -1:
                    newBeat.Duration = Duration.Half;
                    break;
                case 0:
                    newBeat.Duration = Duration.Quarter;
                    break;
                case 1:
                    newBeat.Duration = Duration.Eighth;
                    break;
                case 2:
                    newBeat.Duration = Duration.Sixteenth;
                    break;
                case 3:
                    newBeat.Duration = Duration.ThirtySecond;
                    break;
                case 4:
                    newBeat.Duration = Duration.SixtyFourth;
                    break;
                default:
                    newBeat.Duration = Duration.Quarter;
                    break;
            }

            if ((flags & 0x20) != 0)
            {
                newBeat.TupletNumerator = ReadInt32();
                switch (newBeat.TupletNumerator)
                {
                    case 1:
                        newBeat.TupletDenominator = 1;
                        break;
                    case 3:
                        newBeat.TupletDenominator = 2;
                        break;
                    case 5:
                    case 6:
                    case 7:
                        newBeat.TupletDenominator = 4;
                        break;
                    case 9:
                    case 10:
                    case 11:
                    case 12:
                    case 13:
                        newBeat.TupletDenominator = 8;
                        break;
                    case 2:
                    case 4:
                    case 8:
                        break;
                    default:
                        newBeat.TupletNumerator = 1;
                        newBeat.TupletDenominator = 1;
                        break;
                }
            }

            if ((flags & 0x02) != 0)
            {
                ReadChord(newBeat);
            }

            if ((flags & 0x04) != 0)
            {
                newBeat.Text = ReadStringIntUnused();
            }

            if ((flags & 0x08) != 0)
            {
                ReadBeatEffects(newBeat);
            }

            if ((flags & 0x10) != 0)
            {
                ReadMixTableChange(newBeat);
            }

            var stringFlags = Data.ReadByte();
            for (int i = 6; i >= 0; i--)
            {
                if ((stringFlags & (1 << i)) != 0 && (6 - i) < track.Tuning.Length)
                {
                    ReadNote(track, bar, voice, newBeat, (6 - i));
                }
            }

            if (_versionNumber >= 500)
            {
                Data.ReadByte();
                var flag = Data.ReadByte();
                if ((flag & 0x08) != 0)
                {
                    Data.ReadByte();
                }
            }
        }
 private static void AddBeatAndSilenceToVoice(Voice voice, Duration duration)
 {
     var beat = new Beat();
     beat.Duration = duration;
     voice.AddBeat(beat);
 }
Exemplo n.º 18
0
        public void ReadGrace(Voice voice, Note note)
        {
            var graceBeat = new Beat();
            var graceNote = new Note();
            graceNote.String = note.String;
            graceNote.Fret = Data.ReadSignedByte();
            graceBeat.Duration = Duration.ThirtySecond;
            graceBeat.Dynamic = ToDynamicValue(Data.ReadSignedByte());
            var transition = Data.ReadSignedByte();
            switch (transition)
            {
                case 0: // none
                    break;
                case 1:
                    graceNote.SlideType = SlideType.Legato;
                    graceNote.SlideTarget = note;
                    break;
                case 2: // bend
                    break;
                case 3: // hammer
                    graceNote.IsHammerPullOrigin = true;
                    break;
            }
            graceNote.Dynamic = graceBeat.Dynamic;
            Data.Skip(1); // duration

            if (_versionNumber < 500)
            {
                graceBeat.GraceType = GraceType.BeforeBeat;
            }
            else
            {
                var flags = Data.ReadByte();
                graceNote.IsDead = (flags & 0x01) != 0;
                graceBeat.GraceType = (flags & 0x02) != 0 ? GraceType.OnBeat : GraceType.BeforeBeat;
            }

            graceBeat.AddNote(graceNote);
            voice.AddGraceBeat(graceBeat);
        }
        private static void AddBeatWithChordToVoice(Voice voice, SongChord2014 sourceChord, Duration duration, Single durationTime)
        {
            var beat = new Beat();
            beat.Duration = duration;
            voice.AddBeat(beat);
            beat.ChordId = sourceChord.ChordId.ToString();
            AlphaTab.Model.Chord chord = null;
            try
            {
                chord = beat.Chord;
            }
            catch (KeyNotFoundException)
            {
            }

            //Will be non-null if predefined chord exist (and predefined chord should exist if ChordId is present in ChordTemplates)
            if (chord == null)
            {
                beat.ChordId = null;
                //chord = new global::alphatab.model.Chord();
                //voice.bar.track.chords.set(beat.chordId, chord);

                //Set notes in beat from this chord
                if (sourceChord.ChordNotes != null)
                {
                    foreach (var sourceNote in sourceChord.ChordNotes)
                    {
                        var note1 = NoteFromNote(sourceNote, durationTime);
                        beat.AddNote(note1);
                    }
                }
            }
            else
            {
                //Set notes in beat from predefined chord
                for (int i = 0; i < chord.Strings.Count; i++)
                {
                    var tmpstrFret = chord.Strings[i];
                    if (tmpstrFret > -1)
                    {
                        var note1 = new Note();
                        note1.Fret = tmpstrFret;
                        note1.String = i + 1;
                        beat.AddNote(note1);
                    }
                }
            }
        }
Exemplo n.º 20
0
        public void ReadNoteEffects(Track track, Voice voice, Beat beat, Note note)
        {
            var flags = Data.ReadByte();
            var flags2 = 0;
            if (_versionNumber >= 400)
            {
                flags2 = Data.ReadByte();
            }

            if ((flags & 0x01) != 0)
            {
                ReadBend(note);
            }

            if ((flags & 0x10) != 0)
            {
                ReadGrace(voice, note);
            }

            if ((flags2 & 0x04) != 0)
            {
                ReadTremoloPicking(beat);
            }

            if ((flags2 & 0x08) != 0)
            {
                ReadSlide(note);
            }
            else if (_versionNumber < 400)
            {
                if ((flags & 0x04) != 0)
                {
                    note.SlideType = SlideType.Shift;
                }
            }

            if ((flags2 & 0x10) != 0)
            {
                ReadArtificialHarmonic(note);
            }
            else if (_versionNumber < 400)
            {
                if ((flags & 0x04) != 0)
                {
                    note.HarmonicType = HarmonicType.Natural;
                    note.HarmonicValue = DeltaFretToHarmonicValue(note.Fret);
                }
                if ((flags & 0x08) != 0)
                {
                    note.HarmonicType = HarmonicType.Artificial;
                }
            }

            if ((flags2 & 0x20) != 0)
            {
                ReadTrill(note);
            }

            note.IsLetRing = (flags & 0x08) != 0;
            note.IsHammerPullOrigin = (flags & 0x02) != 0;
            if ((flags2 & 0x40) != 0)
            {
                note.Vibrato = VibratoType.Slight;
            }
            note.IsPalmMute = (flags2 & 0x02) != 0;
            note.IsStaccato = (flags2 & 0x01) != 0;
        }
Exemplo n.º 21
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();        */
        }
Exemplo n.º 22
0
 public static void CopyTo(Voice src, Voice dst)
 {
     dst.Index = src.Index;
 }
Exemplo n.º 23
0
        private void BuildModel()
        {
            // build score
            for (int i = 0, j = _masterBars.Count; i < j; i++)
            {
                var masterBar = _masterBars[i];
                Score.AddMasterBar(masterBar);
            }

            // build tracks (not all, only those used by the score)
            var trackIndex = 0;
            foreach (var trackId in _tracksMapping)
            {
                var track = _tracksById[trackId];
                Score.AddTrack(track);

                // iterate all bar definitions for the masterbars
                // and add the correct bar to the track
                for (int i = 0, j = _barsOfMasterBar.Count; i < j; i++)
                {
                    var barIds = _barsOfMasterBar[i];
                    var barId = barIds[trackIndex];
                    if (barId != InvalidId)
                    {
                        track.AddBar(_barsById[barId]);
                    }
                }

                trackIndex++;
            }

            // build bars
            foreach (var barId in _barsById.Keys)
            {
                var bar = _barsById[barId];
                if (_voicesOfBar.ContainsKey(barId))
                {
                    // add voices to bars
                    foreach (var voiceId in _voicesOfBar[barId])
                    {
                        if (voiceId != InvalidId)
                        {
                            bar.AddVoice(_voiceById[voiceId]);
                        }
                        else
                        {
                            // invalid voice -> empty voice
                            var voice = new Voice();
                            bar.AddVoice(voice);

                            var beat = new Beat();
                            beat.IsEmpty = true;
                            beat.Duration = Duration.Quarter;
                            voice.AddBeat(beat);
                        }
                    }
                }
            }

            // build beats
            foreach (var beatId in _beatById.Keys)
            {
                var beat = _beatById[beatId];
                var rhythmId = _rhythmOfBeat[beatId];
                var rhythm = _rhythmById[rhythmId];

                // set beat duration
                beat.Duration = rhythm.Value;
                beat.Dots = rhythm.Dots;
                beat.TupletNumerator = rhythm.TupletNumerator;
                beat.TupletDenominator = rhythm.TupletDenominator;

                // add notes to beat
                if (_notesOfBeat.ContainsKey(beatId))
                {
                    foreach (var noteId in _notesOfBeat[beatId])
                    {
                        if (noteId != InvalidId)
                        {
                            beat.AddNote(_noteById[noteId]);
                            if (_tappedNotes.ContainsKey(noteId))
                            {
                                beat.Tap = true;
                            }
                        }
                    }
                }
            }

            // build voices
            foreach (var voiceId in _voiceById.Keys)
            {
                var voice = _voiceById[voiceId];
                if (_beatsOfVoice.ContainsKey(voiceId))
                {
                    // add beats to voices
                    foreach (var beatId in _beatsOfVoice[voiceId])
                    {
                        if (beatId != InvalidId)
                        {
                            // important! we clone the beat because beats get reused
                            // in gp6, our model needs to have unique beats.
                            voice.AddBeat(_beatById[beatId].Clone());
                        }
                    }
                }
            }

            // build automations
            foreach (var barId in _automations.Keys)
            {
                var bar = _barsById[barId];
                for (int i = 0, j = bar.Voices.Count; i < j; i++)
                {
                    var v = bar.Voices[i];
                    if (v.Beats.Count > 0)
                    {
                        for (int k = 0, l = _automations[barId].Count; k < l; k++)
                        {
                            var automation = _automations[barId][k];
                            v.Beats[0].Automations.Add(automation);
                        }
                    }
                }
            }

            // build automations
            foreach (var barId in _automations.Keys)
            {
                var automations = _automations[barId];
                var bar = _barsById[barId];
                for (int i = 0, j = automations.Count; i < j; i++)
                {
                    var automation = automations[i];
                    if (automation.Type == AutomationType.Tempo)
                    {
                        if (barId == "0") // // TODO find the correct first bar id
                        {
                            Score.Tempo = (int)(automation.Value);
                            Score.TempoLabel = automation.Text;
                        }

                        bar.MasterBar.TempoAutomation = automation;
                    }
                }
            }
        }
Exemplo n.º 24
0
        private void CreateVoiceGlyphs(Voice v)
        {
            foreach (var b in v.Beats)
            {
                // we create empty glyphs as alignment references and to get the
                // effect bar sized
                var container = new BeatContainerGlyph(b, GetOrCreateVoiceContainer(v), true);
                container.PreNotes = new BeatGlyphBase();
                container.OnNotes = new BeatOnNoteGlyphBase();
                AddBeatGlyph(container);

                if (_info.ShouldCreateGlyph(this, b))
                {
                    CreateOrResizeGlyph(_info.SizingMode, b);
                }
            }
        }
Exemplo n.º 25
0
        public bool CheckBeat(Beat beat)
        {
            if (beat.InvertBeamDirection)
            {
                InvertBeamDirection = true;
            }

            if (Voice == null)
            {
                Voice = beat.Voice;
            }
            // allow adding if there are no beats yet
            var add = false;
            if (Beats.Count == 0)
            {
                add = true;
            }
            else if (CanJoin(_lastBeat, beat))
            {
                add = true;
            }

            if (add)
            {
                _lastBeat = beat;
                Beats.Add(beat);

                if (beat.HasTuplet)
                {
                    HasTuplet = true;
                }

                int fingeringCount = 0;
                for (var n = 0; n < beat.Notes.Count; n++)
                {
                    var note = beat.Notes[n];
                    if (note.LeftHandFinger != Fingers.Unknown || note.RightHandFinger != Fingers.Unknown)
                    {
                        fingeringCount++;
                    }
                }

                if (fingeringCount > FingeringCount)
                {
                    FingeringCount = fingeringCount;
                }

                CheckNote(beat.MinNote);
                CheckNote(beat.MaxNote);
                if (ShortestDuration < beat.Duration)
                {
                    ShortestDuration = beat.Duration;
                }

                if (beat.HasTuplet)
                {
                    HasTuplet = true;
                }
            }

            return add;
        }
Exemplo n.º 26
0
        private void ParseVoice(IXmlNode node)
        {
            var voice = new Voice();
            var voiceId = node.Attributes.Get("id").Value;

            node.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "Beats":
                            _beatsOfVoice[voiceId] = GetValue(c).Split(' ');
                            break;
                    }
                }
            });

            _voiceById[voiceId] = voice;
        }
        private static void AddBeatAndNoteToVoice(Voice voice, SongNote2014 note, Duration duration, Single durationTime)
        {
            var beat = new Beat();
            beat.Duration = duration;
            voice.AddBeat(beat);
            if (note != null)
            {
                var destNote = NoteFromNote(note, durationTime);
                beat.AddNote(destNote);

                if (note.HammerOn == 1 && _prevConvertedNote != null)
                {
                    _prevConvertedNote.IsHammerPullOrigin = true;
                    //_prevConvertedNote.slideTarget = destNote;
                    //_prevConvertedNote.slideType = SlideType.Shift;
                    destNote.IsHammerPullOrigin = false;
                    destNote.IsGhost = true;
                    //_prevConvertedNote.hammerPullOrigin = destNote;// _prevConvertedNote;
                    destNote.HammerPullOrigin = _prevConvertedNote;
                }
                _prevConvertedNote = destNote;
            }
        }
Exemplo n.º 28
0
        private void ParseMeasure(IXmlNode element, Track track, bool isFirstMeasure)
        {
            var barIndex = 0;
            if (isFirstMeasure)
            {
                _trackFirstMeasureNumber = Std.ParseInt(element.GetAttribute("number"));
                barIndex = 0;
            }
            else
            {
                barIndex = Std.ParseInt(element.GetAttribute("number")) - _trackFirstMeasureNumber;
            }

            // create empty bars to the current index
            Bar bar = null;
            MasterBar masterBar = null;
            for (int i = track.Staves[0].Bars.Count; i <= barIndex; i++)
            {
                bar = new Bar();
                masterBar = GetOrCreateMasterBar(barIndex);
                track.AddBarToStaff(0, bar);

                for (int j = 0; j < _maxVoices; j++)
                {
                    var emptyVoice = new Voice();
                    bar.AddVoice(emptyVoice);
                    var emptyBeat = new Beat { IsEmpty = true };
                    emptyVoice.AddBeat(emptyBeat);
                }
            }

            bool chord = false;
            bool isFirstBeat = true;

            element.IterateChildren(c =>
            {
                if (c.NodeType == XmlNodeType.Element)
                {
                    switch (c.LocalName)
                    {
                        case "note":
                            chord = ParseNoteBeat(c, track, bar, chord, isFirstBeat);
                            isFirstBeat = false;
                            break;
                        case "forward":
                            break;
                        case "direction":
                            ParseDirection(c, masterBar);
                            break;
                        case "attributes":
                            ParseAttributes(c, bar, masterBar);
                            break;
                        case "harmony":
                            // TODO
                            break;
                        case "sound":
                            // TODO
                            break;
                        case "barline":
                            // TODO
                            break;
                    }
                }
            });
        }
Exemplo n.º 29
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;
        }
Exemplo n.º 30
0
        private void Beat(Voice voice)
        {
            // duration specifier?
            if (_sy == AlphaTexSymbols.DoubleDot)
            {
                NewSy();
                if (_sy != AlphaTexSymbols.Number)
                {
                    Error("duration", AlphaTexSymbols.Number);
                }

                var duration = (int)_syData;
                switch (duration)
                {
                    case 1:
                    case 2:
                    case 4:
                    case 8:
                    case 16:
                    case 32:
                    case 64:
                        _currentDuration = ParseDuration((int)_syData);
                        break;
                    default:
                        Error("duration", AlphaTexSymbols.Number, false);
                        break;
                }

                NewSy();
                return;
            }

            var beat = new Beat();
            voice.AddBeat(beat);

            if (voice.Bar.MasterBar.TempoAutomation != null && voice.Beats.Count == 1)
            {
                beat.Automations.Add(voice.Bar.MasterBar.TempoAutomation);
            }

            // notes
            if (_sy == AlphaTexSymbols.LParensis)
            {
                NewSy();

                Note(beat);
                while (_sy != AlphaTexSymbols.RParensis && _sy != AlphaTexSymbols.Eof)
                {
                    Note(beat);
                }

                if (_sy != AlphaTexSymbols.RParensis)
                {
                    Error("note-list", AlphaTexSymbols.RParensis);
                }
                NewSy();
            }
            // rest 
            else if (_sy == AlphaTexSymbols.String && _syData.ToString().ToLower() == "r")
            {
                // rest voice -> no notes 
                NewSy();
            }
            else
            {
                Note(beat);
            }

            // new duration
            if (_sy == AlphaTexSymbols.Dot)
            {
                NewSy();
                if (_sy != AlphaTexSymbols.Number)
                {
                    Error("duration", AlphaTexSymbols.Number);
                }

                var duration = (int)_syData;
                switch (duration)
                {
                    case 1:
                    case 2:
                    case 4:
                    case 8:
                    case 16:
                    case 32:
                    case 64:
                        _currentDuration = ParseDuration((int)_syData);
                        break;
                    default:
                        Error("duration", AlphaTexSymbols.Number, false);
                        break;
                }

                NewSy();
            }
            beat.Duration = _currentDuration;

            // beat multiplier (repeat beat n times)
            var beatRepeat = 1;
            if (_sy == AlphaTexSymbols.Multiply)
            {
                NewSy();

                // multiplier count
                if (_sy != AlphaTexSymbols.Number)
                {
                    Error("multiplier", AlphaTexSymbols.Number);
                }
                else
                {
                    beatRepeat = (int)_syData;
                }
                NewSy();
            }

            BeatEffects(beat);

            for (var i = 0; i < beatRepeat - 1; i++)
            {
                voice.AddBeat(beat.Clone());
            }
        }
Exemplo n.º 31
0
 internal static void CopyTo(Voice src, Voice dst)
 {
     dst.Index   = src.Index;
     dst.IsEmpty = src.IsEmpty;
 }