From fae88c8b88eba18272b73f48a769ba0a5efc84b2 Mon Sep 17 00:00:00 2001 From: jules Date: Wed, 17 Oct 2012 17:03:05 +0100 Subject: [PATCH] Minor documentation updates. Added MidiMessageSequence::sort() method. --- .../Code Editor/jucer_SourceCodeEditor.h | 2 +- .../midi/juce_MidiMessageSequence.cpp | 50 +++++++++++-------- .../midi/juce_MidiMessageSequence.h | 5 ++ modules/juce_core/files/juce_File.h | 4 +- modules/juce_core/streams/juce_InputStream.h | 12 ++--- 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.h b/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.h index 9cb0899502..9f05e77a05 100644 --- a/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.h +++ b/extras/Introjucer/Source/Code Editor/jucer_SourceCodeEditor.h @@ -38,7 +38,7 @@ public: bool loadedOk() const { return true; } bool isForFile (const File& file) const { return getFile() == file; } - bool isForNode (const ValueTree& node) const { return false; } + bool isForNode (const ValueTree&) const { return false; } bool refersToProject (Project& p) const { return project == &p; } Project* getProject() const { return project; } String getName() const { return getFile().getFileName(); } diff --git a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp index 42bbb4610e..8b5de6d773 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp @@ -68,19 +68,19 @@ MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (cons double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const { - const MidiEventHolder* const meh = list [index]; + if (const MidiEventHolder* const meh = list [index]) + if (meh->noteOffObject != nullptr) + return meh->noteOffObject->message.getTimeStamp(); - if (meh != nullptr && meh->noteOffObject != nullptr) - return meh->noteOffObject->message.getTimeStamp(); - else - return 0.0; + return 0.0; } int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const { - const MidiEventHolder* const meh = list [index]; + if (const MidiEventHolder* const meh = list [index]) + return list.indexOf (meh->noteOffObject); - return meh != nullptr ? list.indexOf (meh->noteOffObject) : -1; + return -1; } int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const @@ -113,8 +113,10 @@ double MidiMessageSequence::getEndTime() const double MidiMessageSequence::getEventTime (const int index) const { - const MidiEventHolder* const e = list [index]; - return e != nullptr ? e->message.getTimeStamp() : 0.0; + if (const MidiEventHolder* const meh = list [index]) + return meh->message.getTimeStamp(); + + return 0.0; } //============================================================================== @@ -179,20 +181,26 @@ void MidiMessageSequence::addSequence (const MidiMessageSequence& other, } } + sort(); +} + +//============================================================================== +void MidiMessageSequence::sort() +{ MidiMessageSequenceSorter sorter; list.sort (sorter, true); } -//============================================================================== void MidiMessageSequence::updateMatchedPairs() { for (int i = 0; i < list.size(); ++i) { - const MidiMessage& m1 = list.getUnchecked(i)->message; + MidiEventHolder* const meh = list.getUnchecked(i); + const MidiMessage& m1 = meh->message; if (m1.isNoteOn()) { - list.getUnchecked(i)->noteOffObject = nullptr; + meh->noteOffObject = nullptr; const int note = m1.getNoteNumber(); const int chan = m1.getChannel(); const int len = list.size(); @@ -205,14 +213,14 @@ void MidiMessageSequence::updateMatchedPairs() { if (m.isNoteOff()) { - list.getUnchecked(i)->noteOffObject = list[j]; + meh->noteOffObject = list[j]; break; } else if (m.isNoteOn()) { list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note))); list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp()); - list.getUnchecked(i)->noteOffObject = list[j]; + meh->noteOffObject = list[j]; break; } } @@ -224,8 +232,10 @@ void MidiMessageSequence::updateMatchedPairs() void MidiMessageSequence::addTimeToMessages (const double delta) { for (int i = list.size(); --i >= 0;) - list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp() - + delta); + { + MidiMessage& mm = list.getUnchecked(i)->message; + mm.setTimeStamp (m.getTimeStamp() + delta); + } } //============================================================================== @@ -237,11 +247,8 @@ void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToE { const MidiMessage& mm = list.getUnchecked(i)->message; - if (mm.isForChannel (channelNumberToExtract) - || (alsoIncludeMetaEvents && mm.isMetaEvent())) - { + if (mm.isForChannel (channelNumberToExtract) || (alsoIncludeMetaEvents && mm.isMetaEvent())) destSequence.addEvent (mm); - } } } @@ -284,8 +291,7 @@ void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumbe { const MidiMessage& mm = list.getUnchecked(i)->message; - if (mm.isForChannel (channelNumber) - && mm.getTimeStamp() <= time) + if (mm.isForChannel (channelNumber) && mm.getTimeStamp() <= time) { if (mm.isProgramChange()) { diff --git a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h index eec33d14ba..cc83463403 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h +++ b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h @@ -199,6 +199,11 @@ public: */ void updateMatchedPairs(); + /** Forces a sort of the sequence. + You may need to call this if you've manually modified the timestamps of some + events such that the overall order now needs updating. + */ + void sort(); //============================================================================== /** Copies all the messages for a particular midi channel to another sequence. diff --git a/modules/juce_core/files/juce_File.h b/modules/juce_core/files/juce_File.h index 555ea3d4b2..411eb4ae27 100644 --- a/modules/juce_core/files/juce_File.h +++ b/modules/juce_core/files/juce_File.h @@ -605,8 +605,8 @@ public: Attempts to load the entire file as a zero-terminated string. - This makes use of InputStream::readEntireStreamAsString, which should - automatically cope with unicode/acsii file formats. + This makes use of InputStream::readEntireStreamAsString, which can + read either UTF-16 or UTF-8 file formats. */ String loadFileAsString() const; diff --git a/modules/juce_core/streams/juce_InputStream.h b/modules/juce_core/streams/juce_InputStream.h index 187f219c98..8748a57815 100644 --- a/modules/juce_core/streams/juce_InputStream.h +++ b/modules/juce_core/streams/juce_InputStream.h @@ -217,7 +217,7 @@ public: virtual int readCompressedInt(); //============================================================================== - /** Reads a UTF8 string from the stream, up to the next linefeed or carriage return. + /** Reads a UTF-8 string from the stream, up to the next linefeed or carriage return. This will read up to the next "\n" or "\r\n" or end-of-stream. @@ -227,10 +227,10 @@ public: */ virtual String readNextLine(); - /** Reads a zero-terminated UTF8 string from the stream. + /** Reads a zero-terminated UTF-8 string from the stream. - This will read characters from the stream until it hits a zero character or - end-of-stream. + This will read characters from the stream until it hits a null character + or end-of-stream. @see OutputStream::writeString, readEntireStreamAsString */ @@ -238,8 +238,8 @@ public: /** Tries to read the whole stream and turn it into a string. - This will read from the stream's current position until the end-of-stream, and - will try to make an educated guess about whether it's unicode or an 8-bit encoding. + This will read from the stream's current position until the end-of-stream. + It can read from either UTF-16 or UTF-8 formats. */ virtual String readEntireStreamAsString();