public PatternActionResult Invoke(long time, PatternContext context)
        {
            var programEvents = Program.GetProgramEvents(context.Channel);
            var timedEvents   = programEvents.Select(e => new TimedEvent(e, time));

            return(new PatternActionResult(time, timedEvents));
        }
Exemple #2
0
        /// <summary>
        /// Exports the current <see cref="Pattern"/> to track chunk.
        /// </summary>
        /// <param name="tempoMap">Tempo map to process pattern data according with.</param>
        /// <param name="channel">Channel of notes that will be generated by pattern.</param>
        /// <returns>The <see cref="TrackChunk"/> containing notes events generated by the current <see cref="Pattern"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="tempoMap"/> is null.</exception>
        public TrackChunk ToTrackChunk(TempoMap tempoMap, FourBitNumber channel)
        {
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

            var context = new PatternContext(tempoMap, channel);
            var result  = InvokeActions(0, context);

            //

            var trackChunk = new TrackChunk();

            using (var notesManager = trackChunk.ManageNotes())
            {
                notesManager.Notes.Add(result.Notes ?? Enumerable.Empty <Note>());
            }

            using (var eventsManager = trackChunk.ManageTimedEvents())
            {
                eventsManager.Events.Add(result.Events ?? Enumerable.Empty <TimedEvent>());
            }

            //

            return(trackChunk);
        }
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            var programEvent = Program.GetProgramEvent();
            var timedEvent   = new TimedEvent(programEvent, time);

            return(new PatternActionResult(time, new[] { timedEvent }));
        }
Exemple #4
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            var programChangeEvent = new ProgramChangeEvent(ProgramNumber);
            var timedEvent         = new TimedEvent(programChangeEvent, time);

            return(new PatternActionResult(time, new[] { timedEvent }));
        }
Exemple #5
0
        internal PatternActionResult InvokeActions(long time, PatternContext context)
        {
            var notes  = new List <Note>();
            var events = new List <TimedEvent>();

            foreach (var action in Actions)
            {
                var actionResult = action.Invoke(time, context);

                var newTime = actionResult.Time;
                if (newTime != null)
                {
                    time = newTime.Value;
                }

                var addedNotes = actionResult.Notes;
                if (addedNotes != null)
                {
                    notes.AddRange(addedNotes);
                }

                var addedEvents = actionResult.Events;
                if (addedEvents != null)
                {
                    events.AddRange(addedEvents);
                }
            }

            return(new PatternActionResult(time, notes, events));
        }
Exemple #6
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            var textEvent  = (BaseTextEvent)Activator.CreateInstance(typeof(TEvent), Text);
            var timedEvent = new TimedEvent(textEvent, time);

            return(new PatternActionResult(time, new[] { timedEvent }));
        }
Exemple #7
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            context.SaveTime(time);

            var newContext = new PatternContext(context.TempoMap, context.Channel);

            return(Pattern.InvokeActions(time, newContext));
        }
Exemple #8
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            var tempoMap = context.TempoMap;

            context.SaveTime(time);

            var convertedTime = TimeConverter.ConvertFrom(new MathTime(time, Step, MathOperation.Subtract), tempoMap);

            return(new PatternActionResult(Math.Max(convertedTime, 0)));
        }
Exemple #9
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            var tempoMap = context.TempoMap;

            context.SaveTime(time);

            var convertedTime = TimeConverter.ConvertFrom(((MidiTimeSpan)time).Subtract(Step, TimeSpanMode.TimeLength), tempoMap);

            return(new PatternActionResult(Math.Max(convertedTime, 0)));
        }
Exemple #10
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            context.SaveTime(time);

            var chordLength = LengthConverter.ConvertFrom(Length, time, context.TempoMap);

            return(new PatternActionResult(time + chordLength,
                                           NoteDefinitions.Select(d => new Note(d.NoteNumber, chordLength, time)
            {
                Channel = context.Channel,
                Velocity = Velocity
            })));
        }
Exemple #11
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            var programEvents = Program.GetProgramEvents();

            foreach (var channelEvent in programEvents.OfType <ChannelEvent>())
            {
                channelEvent.Channel = context.Channel;
            }

            var timedEvents = programEvents.Select(e => new TimedEvent(e, time));

            return(new PatternActionResult(time, timedEvents));
        }
Exemple #12
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            context.SaveTime(time);

            var noteLength = LengthConverter.ConvertFrom(Length, time, context.TempoMap);

            var note = new Note(Note.NoteNumber, noteLength, time)
            {
                Channel  = context.Channel,
                Velocity = Velocity
            };

            return(new PatternActionResult(time + noteLength, new[] { note }));
        }
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            var anchorTimes = context.GetAnchorTimes(Anchor);
            var newTime     = 0L;

            switch (AnchorPosition)
            {
            case AnchorPosition.First:
                newTime = anchorTimes.First();
                break;

            case AnchorPosition.Last:
                newTime = anchorTimes.Last();
                break;

            case AnchorPosition.Nth:
                newTime = anchorTimes[Index];
                break;
            }

            return(new PatternActionResult(newTime));
        }