/// <summary> /// Rebuilds the sequence properties to match length and track count - will destroy contents /// </summary> public virtual void ApplySequencerLengthToSequence() { if (Sequence == null) { return; } float beatDuration = 60f / BPM; Sequence.TargetBPM = BPM; Sequence.Length = SequencerLength * beatDuration; Sequence.EndSilenceDuration = beatDuration; Sequence.Quantized = true; if ((LastSequencerLength != SequencerLength) || (LastTracksCount != Sequence.SequenceTracks.Count)) { Sequence.QuantizedSequence = new List <MMSequenceList>(); for (int trackIndex = 0; trackIndex < Sequence.SequenceTracks.Count; trackIndex++) { Sequence.QuantizedSequence.Add(new MMSequenceList()); Sequence.QuantizedSequence[trackIndex].Line = new List <MMSequenceNote>(); for (int i = 0; i < SequencerLength; i++) { MMSequenceNote note = new MMSequenceNote(); note.ID = -1; note.Timestamp = i * beatDuration; Sequence.QuantizedSequence[trackIndex].Line.Add(note); } } } LastTracksCount = Sequence.SequenceTracks.Count; LastSequencerLength = SequencerLength; }
public virtual MMSequenceNote Copy() { MMSequenceNote newNote = new MMSequenceNote(); newNote.ID = this.ID; newNote.Timestamp = this.Timestamp; return(newNote); }
/// <summary> /// Makes sure we have a scriptable object to record to /// </summary> public virtual void Initialization() { Recording = false; _note = new MMSequenceNote(); if (SequenceScriptableObject == null) { Debug.LogError(this.name + " this input based sequencer needs a bound scriptable object to function, please create one and bind it in the inspector."); } }
/// <summary> /// Adds a note to the specified track /// </summary> /// <param name="track"></param> public virtual void AddNoteToTrack(MMSequenceTrack track) { if ((SequenceScriptableObject.OriginalSequence.Line.Count == 0) && RemoveInitialSilence) { _recordingStartedAt = Time.realtimeSinceStartup; } _note = new MMSequenceNote(); _note.ID = track.ID; _note.Timestamp = Time.realtimeSinceStartup + RecordingStartOffset - _recordingStartedAt; SequenceScriptableObject.OriginalSequence.Line.Add(_note); }
/// <summary> /// Adds one column at the end of the sequence /// </summary> public virtual void IncrementLength() { if (Sequence == null) { return; } float beatDuration = 60f / BPM; SequencerLength++; Sequence.Length = SequencerLength * beatDuration; LastSequencerLength = SequencerLength; for (int trackIndex = 0; trackIndex < Sequence.SequenceTracks.Count; trackIndex++) { MMSequenceNote newNote = new MMSequenceNote(); newNote.ID = -1; newNote.Timestamp = Sequence.QuantizedSequence[trackIndex].Line.Count * beatDuration; Sequence.QuantizedSequence[trackIndex].Line.Add(newNote); } }
/// <summary> /// Makes every timestamp in the sequence match the BPM track /// </summary> public virtual void QuantizeSequenceToBPM(List <MMSequenceNote> baseSequence) { float sequenceLength = Length; float beatDuration = 60f / TargetBPM; int numberOfBeatsInSequence = (int)(sequenceLength / beatDuration); QuantizedSequence = new List <MMSequenceList>(); _deleteList = new List <MMSequenceNote>(); _deleteList.Clear(); // we fill the BPM track with the computed timestamps _quantizedBeats = new float[numberOfBeatsInSequence]; for (int i = 0; i < numberOfBeatsInSequence; i++) { _quantizedBeats[i] = i * beatDuration; } for (int i = 0; i < SequenceTracks.Count; i++) { QuantizedSequence.Add(new MMSequenceList()); QuantizedSequence[i].Line = new List <MMSequenceNote>(); for (int j = 0; j < numberOfBeatsInSequence; j++) { MMSequenceNote newNote = new MMSequenceNote(); newNote.ID = -1; newNote.Timestamp = _quantizedBeats[j]; QuantizedSequence[i].Line.Add(newNote); foreach (MMSequenceNote note in baseSequence) { float newTimestamp = RoundFloatToArray(note.Timestamp, _quantizedBeats); if ((newTimestamp == _quantizedBeats[j]) && (note.ID == SequenceTracks[i].ID)) { QuantizedSequence[i].Line[j].ID = note.ID; } } } } }
/// <summary> /// Compares and sorts two sequence notes /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> static int SortByTimestamp(MMSequenceNote p1, MMSequenceNote p2) { return(p1.Timestamp.CompareTo(p2.Timestamp)); }