void RemoveNote(ref SeqCommand command) { var pos = command.IntValue1; if (pos >= 0) { _notePosition.RemoveAt(pos); _notes.RemoveAt(pos); } }
public void AddNote(int bar, float sub, float length, float frequency, float velocity) { _sequencer.AddCommand( SeqCommand.InsertNote( position: RatioToSampleTime(bar, sub), length: RatioToSampleTime(0, length), frequency: frequency, velocity: velocity ) ); }
void ScaleNotes(ref SeqCommand command) { var newLength = command.IntValue1; var factor = ((double)newLength) / TotalLength; for (int i = 0; i < _notePosition.Count; i++) { _notePosition[i] = (int)Math.Round(factor * _notePosition[i]); var note = _notes[i]; note.Length = (int)Math.Round(factor * note.Length); _notes[i] = note; } }
void ApplyCommand(ref SeqCommand command) { switch (command.Type) { case SeqCommand.CommandType.SetLength: TotalLength = command.IntValue1; break; case SeqCommand.CommandType.Start: IsRunning = true; break; case SeqCommand.CommandType.Stop: IsRunning = false; break; case SeqCommand.CommandType.SetLoop: IsLooping = true; break; case SeqCommand.CommandType.UnsetLoop: IsLooping = false; break; case SeqCommand.CommandType.InsertNote: InsertNote(ref command); break; case SeqCommand.CommandType.RemoveNote: RemoveNote(ref command); break; case SeqCommand.CommandType.ScaleNotes: ScaleNotes(ref command); break; default: break; } }
void InsertNote(ref SeqCommand command) { var note = new SeqNote { Length = command.IntValue2, Frequency = command.FloatValue1, Velocity = command.FloatValue2, }; var pos = _notePosition.BinarySearch(command.IntValue1); if (pos < 0) { _notePosition.Insert(~pos, command.IntValue1); _notes.Insert(~pos, note); } else { _notePosition[pos] = command.IntValue1; _notes[pos] = note; } }
public void SetLength(int bars) { _sequencer.AddCommand( SeqCommand.SetLength((int)Math.Ceiling(BarsToSeconds(bars) * SampleRate)) ); }
void EnableLoop() { _sequencer.AddCommand(SeqCommand.SetLoop()); }
public void AddCommand(SeqCommand command) { _commands.Enqueue((command)); }