Ejemplo n.º 1
0
 public void AddBeat(BeatTickLookup beat)
 {
     var track = beat.Beat.Voice.Bar.Staff.Track.Index;
     if (!BeatsPerTrack.ContainsKey(track))
     {
         BeatsPerTrack[track] = new FastList<BeatTickLookup>();
     }
     BeatsPerTrack[track].Add(beat);
 }
Ejemplo n.º 2
0
 public void AddBeat(BeatTickLookup beat)
 {
     _currentMasterBar.AddBeat(beat);
 }
Ejemplo n.º 3
0
        public MidiTickLookupFindBeatResult FindBeat(Track[] tracks, int tick)
        {
            // get all beats within the masterbar
            var masterBar = FindMasterBar(tick);

            if (masterBar == null)
            {
                return(null);
            }

            var trackLookup = new FastDictionary <int, bool>();

            foreach (var track in tracks)
            {
                trackLookup[track.Index] = true;
            }

            BeatTickLookup beat  = null;
            int            index = 0;
            var            beats = masterBar.Beats;

            for (int b = 0; b < beats.Count; b++)
            {
                // is the current beat played on the given tick?
                var currentBeat = beats[b];
                // skip non relevant beats
                if (!trackLookup.ContainsKey(currentBeat.Beat.Voice.Bar.Staff.Track.Index))
                {
                    continue;
                }
                if (currentBeat.Start <= tick && tick < currentBeat.End)
                {
                    // take the latest played beat we can find. (most right)
                    if (beat == null || (beat.Start < currentBeat.Start))
                    {
                        beat  = beats[b];
                        index = b;
                    }
                }
                // if we are already past the tick, we can stop searching
                else if (currentBeat.End > tick)
                {
                    break;
                }
            }

            if (beat == null)
            {
                return(null);
            }

            // search for next relevant beat in masterbar
            BeatTickLookup nextBeat = null;

            for (int b = index + 1; b < beats.Count; b++)
            {
                var currentBeat = beats[b];
                if (trackLookup.ContainsKey(currentBeat.Beat.Voice.Bar.Staff.Track.Index))
                {
                    nextBeat = currentBeat;
                    break;
                }
            }

            // first relevant beat in next bar
            if (nextBeat == null && masterBar.MasterBar.NextMasterBar != null)
            {
                var nextBar = GetMasterBar(masterBar.MasterBar.NextMasterBar);
                beats = nextBar.Beats;
                for (int b = 0; b < beats.Count; b++)
                {
                    var currentBeat = beats[b];
                    if (trackLookup.ContainsKey(currentBeat.Beat.Voice.Bar.Staff.Track.Index))
                    {
                        nextBeat = currentBeat;
                        break;
                    }
                }
            }

            var result = new MidiTickLookupFindBeatResult();

            result.CurrentBeat = beat.Beat;
            result.NextBeat    = nextBeat == null ? null : nextBeat.Beat;
            result.Duration    = MidiUtils.TicksToMillis(beat.End - beat.Start, masterBar.Tempo);
            return(result);
        }
Ejemplo n.º 4
0
 public void AddBeat(BeatTickLookup beat)
 {
     _currentMasterBar.AddBeat(beat);
 }
Ejemplo n.º 5
0
        private void GenerateBeat(Beat beat, int barStartTick)
        {
            // TODO: take care of tripletfeel
            var beatStart = beat.Start;
            var duration = beat.CalculateDuration();

            var beatLookup = new BeatTickLookup();
            beatLookup.Start = barStartTick + beatStart;
            beatLookup.End = barStartTick + beatStart + duration;
            beatLookup.Beat = beat;
            TickLookup.AddBeat(beatLookup);

            var track = beat.Voice.Bar.Staff.Track;

            for (int i = 0, j = beat.Automations.Count; i < j; i++)
            {
                GenerateAutomation(beat, beat.Automations[i], barStartTick);
            }

            if (beat.IsRest)
            {
                _handler.AddRest(track.Index, barStartTick + beatStart, track.PlaybackInfo.PrimaryChannel);
            }
            else
            {
                var brushInfo = GetBrushInfo(beat);

                for (int i = 0, j = beat.Notes.Count; i < j; i++)
                {
                    var n = beat.Notes[i];

                    GenerateNote(n, barStartTick + beatStart, duration, brushInfo);
                }
            }

            if (beat.Vibrato != VibratoType.None)
            {
                const int phaseLength = 240; // ticks
                const int bendAmplitude = 3;

                GenerateVibratorWithParams(beat.Voice.Bar.Staff.Track, barStartTick + beatStart, beat.CalculateDuration(), phaseLength, bendAmplitude);
            }
        }