New Class to handle UI
[juce-lv2.git] / juce / source / src / audio / midi / juce_MidiMessageCollector.h
bloba294904d3fef9682348986c02aa9b66a5f113ca7
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_MIDIMESSAGECOLLECTOR_JUCEHEADER__
27 #define __JUCE_MIDIMESSAGECOLLECTOR_JUCEHEADER__
29 #include "juce_MidiInput.h"
30 #include "juce_MidiKeyboardState.h"
33 //==============================================================================
34 /**
35 Collects incoming realtime MIDI messages and turns them into blocks suitable for
36 processing by a block-based audio callback.
38 The class can also be used as either a MidiKeyboardStateListener or a MidiInputCallback
39 so it can easily use a midi input or keyboard component as its source.
41 @see MidiMessage, MidiInput
43 class JUCE_API MidiMessageCollector : public MidiKeyboardStateListener,
44 public MidiInputCallback
46 public:
47 //==============================================================================
48 /** Creates a MidiMessageCollector. */
49 MidiMessageCollector();
51 /** Destructor. */
52 ~MidiMessageCollector();
54 //==============================================================================
55 /** Clears any messages from the queue.
57 You need to call this method before starting to use the collector, so that
58 it knows the correct sample rate to use.
60 void reset (double sampleRate);
62 /** Takes an incoming real-time message and adds it to the queue.
64 The message's timestamp is taken, and it will be ready for retrieval as part
65 of the block returned by the next call to removeNextBlockOfMessages().
67 This method is fully thread-safe when overlapping calls are made with
68 removeNextBlockOfMessages().
70 void addMessageToQueue (const MidiMessage& message);
72 /** Removes all the pending messages from the queue as a buffer.
74 This will also correct the messages' timestamps to make sure they're in
75 the range 0 to numSamples - 1.
77 This call should be made regularly by something like an audio processing
78 callback, because the time that it happens is used in calculating the
79 midi event positions.
81 This method is fully thread-safe when overlapping calls are made with
82 addMessageToQueue().
84 void removeNextBlockOfMessages (MidiBuffer& destBuffer, int numSamples);
87 //==============================================================================
88 /** @internal */
89 void handleNoteOn (MidiKeyboardState* source, int midiChannel, int midiNoteNumber, float velocity);
90 /** @internal */
91 void handleNoteOff (MidiKeyboardState* source, int midiChannel, int midiNoteNumber);
92 /** @internal */
93 void handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message);
95 private:
96 //==============================================================================
97 double lastCallbackTime;
98 CriticalSection midiCallbackLock;
99 MidiBuffer incomingMessages;
100 double sampleRate;
102 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiMessageCollector);
106 #endif // __JUCE_MIDIMESSAGECOLLECTOR_JUCEHEADER__