Esempio n. 1
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 eventsManager = trackChunk.ManageTimedEvents())
            {
                eventsManager.Events.Add(result.Events ?? Enumerable.Empty <TimedEvent>());
            }

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

            //

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

            return(new PatternActionResult(time, new[] { timedEvent }));
        }
Esempio n. 3
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 }));
        }
        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));
        }
Esempio n. 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));
        }
Esempio n. 6
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State != PatternActionState.Enabled)
            {
                return(PatternActionResult.DoNothing);
            }

            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));
        }
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State != PatternActionState.Enabled)
            {
                return(PatternActionResult.DoNothing);
            }

            context.SaveTime(time);
            return(new PatternActionResult(time + LengthConverter.ConvertFrom(Step, time, context.TempoMap)));
        }
Esempio n. 8
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)));
        }
Esempio n. 9
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            var programChangeEvent = new ProgramChangeEvent(ProgramNumber)
            {
                Channel = context.Channel
            };
            var timedEvent = new TimedEvent(programChangeEvent, time);

            return(new PatternActionResult(time, new[] { timedEvent }));
        }
Esempio n. 10
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            if (Time != null)
            {
                context.SaveTime(time);
            }

            return(new PatternActionResult(Time != null
                ? TimeConverter.ConvertFrom(Time, context.TempoMap)
                : context.RestoreTime()));
        }
Esempio n. 11
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 <c>null</c>.</exception>
        public TrackChunk ToTrackChunk(TempoMap tempoMap, FourBitNumber channel)
        {
            ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap);

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

            return(((IEnumerable <ITimedObject>)result.Events ?? Enumerable.Empty <TimedEvent>())
                   .Concat(result.Notes ?? Enumerable.Empty <Note>())
                   .ToTrackChunk());
        }
Esempio n. 12
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State != PatternActionState.Enabled)
            {
                return(PatternActionResult.DoNothing);
            }

            var programEvents = Program.GetProgramEvents(context.Channel);
            var timedEvents   = programEvents.Select(e => new TimedEvent(e, time));

            return(new PatternActionResult(time, timedEvents));
        }
Esempio n. 13
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State != PatternActionState.Enabled)
            {
                return(PatternActionResult.DoNothing);
            }

            var programEvent = Program.GetProgramEvent(context.Channel);
            var timedEvent   = new TimedEvent(programEvent, time);

            return(new PatternActionResult(time, new[] { timedEvent }));
        }
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State != PatternActionState.Enabled)
            {
                return(PatternActionResult.DoNothing);
            }

            var textEvent  = (BaseTextEvent)Activator.CreateInstance(typeof(TEvent), Text);
            var timedEvent = new TimedEvent(textEvent, time);

            return(new PatternActionResult(time, new[] { timedEvent }));
        }
Esempio n. 15
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            context.SaveTime(time);

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

            return(new PatternActionResult(time + chordLength,
                                           ChordDescriptor.Notes.Select(d => new Note(d.NoteNumber, chordLength, time)
            {
                Channel = context.Channel,
                Velocity = ChordDescriptor.Velocity
            })));
        }
Esempio n. 16
0
        public PatternActionResult Invoke(long time, PatternContext context)
        {
            context.SaveTime(time);

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

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

            return(new PatternActionResult(time + noteLength, new[] { note }));
        }
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State != PatternActionState.Enabled)
            {
                return(PatternActionResult.DoNothing);
            }

            if (Time != null)
            {
                context.SaveTime(time);
            }

            return(new PatternActionResult(Time != null
                ? TimeConverter.ConvertFrom(Time, context.TempoMap)
                : context.RestoreTime()));
        }
Esempio n. 18
0
        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));
        }
Esempio n. 19
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State == PatternActionState.Excluded)
            {
                return(PatternActionResult.DoNothing);
            }

            context.SaveTime(time);

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

            if (State == PatternActionState.Disabled)
            {
                return(new PatternActionResult(time + chordLength));
            }

            return(new PatternActionResult(time + chordLength,
                                           ChordDescriptor.Notes.Select(d => new Note(d.NoteNumber, chordLength, time)
            {
                Channel = context.Channel,
                Velocity = ChordDescriptor.Velocity
            })));
        }
Esempio n. 20
0
        public override PatternActionResult Invoke(long time, PatternContext context)
        {
            if (State == PatternActionState.Excluded)
            {
                return(PatternActionResult.DoNothing);
            }

            context.SaveTime(time);

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

            if (State == PatternActionState.Disabled)
            {
                return(new PatternActionResult(time + noteLength));
            }

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

            return(new PatternActionResult(time + noteLength, new[] { note }));
        }
Esempio n. 21
0
 public override PatternActionResult Invoke(long time, PatternContext context)
 {
     context.SaveTime(time);
     return(new PatternActionResult(time + LengthConverter.ConvertFrom(Step, time, context.TempoMap)));
 }
Esempio n. 22
0
 public abstract PatternActionResult Invoke(long time, PatternContext context);