/// <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); }
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 })); }
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)); }
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)); }
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))); }
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))); }
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 })); }
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())); }
/// <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()); }
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)); }
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 })); }
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 }))); }
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())); }
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)); }
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 }))); }
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 })); }
public override PatternActionResult Invoke(long time, PatternContext context) { context.SaveTime(time); return(new PatternActionResult(time + LengthConverter.ConvertFrom(Step, time, context.TempoMap))); }
public abstract PatternActionResult Invoke(long time, PatternContext context);