From b5354e5949e697992c9999905686a35d07459bb6 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 6 Mar 2021 21:57:58 +0000 Subject: [PATCH] Add num tracks info to midifile Signed-off-by: falkTX --- source/native-plugins/midi-base.hpp | 9 +++++++++ source/native-plugins/midi-file.cpp | 29 ++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/source/native-plugins/midi-base.hpp b/source/native-plugins/midi-base.hpp index 0d7b67227..a0ade99de 100644 --- a/source/native-plugins/midi-base.hpp +++ b/source/native-plugins/midi-base.hpp @@ -473,6 +473,15 @@ private: return; } + if (const RawMidiEvent* const lastEvent = fData.getLast(nullptr)) + { + if (event->time >= lastEvent->time) + { + fData.append(event); + return; + } + } + for (LinkedList::Itenerator it = fData.begin2(); it.valid(); it.next()) { const RawMidiEvent* const oldEvent(it.getValue(nullptr)); diff --git a/source/native-plugins/midi-file.cpp b/source/native-plugins/midi-file.cpp index f2526c847..2cd5a4975 100644 --- a/source/native-plugins/midi-file.cpp +++ b/source/native-plugins/midi-file.cpp @@ -31,6 +31,7 @@ public: kParameterRepeating, kParameterHostSync, kParameterEnabled, + kParameterInfoNumTracks, kParameterInfoLength, kParameterInfoPosition, kParameterCount @@ -49,7 +50,8 @@ public: fWasPlayingBefore(false), fLastPosition(0.0f), fMidiOut(this), - fFileLength(0.0), + fFileLength(0.0f), + fNumTracks(0.0f), fInternalTransportFrame(0), fMaxFrame(0), fLastFrame(0), @@ -113,6 +115,16 @@ protected: param.ranges.max = 1.0f; param.designation = NATIVE_PARAMETER_DESIGNATION_ENABLED; break; + case kParameterInfoNumTracks: + param.name = "Num Tracks"; + param.hints = static_cast(NATIVE_PARAMETER_IS_AUTOMABLE| + NATIVE_PARAMETER_IS_ENABLED| + NATIVE_PARAMETER_IS_INTEGER| + NATIVE_PARAMETER_IS_OUTPUT); + param.ranges.def = 0.0f; + param.ranges.min = 0.0f; + param.ranges.max = 256.0f; + break; case kParameterInfoLength: param.name = "Length"; param.hints = static_cast(NATIVE_PARAMETER_IS_AUTOMABLE| @@ -150,8 +162,10 @@ protected: return fHostSync ? 1.0f : 0.0f; case kParameterEnabled: return fEnabled ? 1.0f : 0.0f; + case kParameterInfoNumTracks: + return fNumTracks; case kParameterInfoLength: - return static_cast(fFileLength); + return fFileLength; case kParameterInfoPosition: return fLastPosition; default: @@ -332,7 +346,8 @@ private: bool fWasPlayingBefore; float fLastPosition; MidiPattern fMidiOut; - double fFileLength; + float fFileLength; + float fNumTracks; uint32_t fInternalTransportFrame; uint32_t fMaxFrame; uint64_t fLastFrame; @@ -342,6 +357,8 @@ private: { fMidiOut.clear(); fInternalTransportFrame = 0; + fFileLength = 0.0f; + fNumTracks = 0.0f; fMaxFrame = 0; fLastFrame = 0; fLastPosition = 0.0f; @@ -363,8 +380,9 @@ private: midiFile.convertTimestampTicksToSeconds(); const double sampleRate = getSampleRate(); + const size_t numTracks = midiFile.getNumTracks(); - for (size_t i=0, numTracks = midiFile.getNumTracks(); i(midiFile.getLastTimestamp()); + fNumTracks = static_cast(numTracks); fNeedsAllNotesOff = true; fInternalTransportFrame = 0; fLastFrame = 0;