Allolib  1.0
C++ Components For Interactive Multimedia
al_SequencerMIDI.hpp
1 #ifndef AL_SEQUENCERMIDI_H
2 #define AL_SEQUENCERMIDI_H
3 
4 /* Allocore --
5  Multimedia / virtual environment application class library
6 
7  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology,
8  UCSB. Copyright (C) 2012-2015. The Regents of the University of California.
9  All rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are
13  met:
14 
15  Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17 
18  Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the following disclaimer in the
20  documentation and/or other materials provided with the
21  distribution.
22 
23  Neither the name of the University of California nor the names
24  of its contributors may be used to endorse or promote products derived from
25  this software without specific prior written permission.
26 
27  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
31  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
34  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39  File description:
40  Class to connect MIDI Input to SynthSequencer objects
41  File author(s):
42  AndrĂ©s Cabrera mantaraya36@gmail.com
43 */
44 
45 #include "al/io/al_MIDI.hpp"
46 #include "al/scene/al_SynthSequencer.hpp"
47 
48 namespace al {
49 
80 public:
81  SequencerMIDI() {}
82 
83  SequencerMIDI(int deviceIndex);
84 
85  SequencerMIDI(int deviceIndex, PolySynth &synth);
86 
87  void open(int deviceIndex, PolySynth &synth);
88 
89  void open(int deviceIndex);
90 
91  // [[deprecated("Use open()")]] void init(int deviceIndex, PolySynth &synth);
92 
93  void close();
94 
95  bool isOpen();
96 
97  void setSynthSequencer(PolySynth &synth) { mSynth = &synth; }
98 
99  void connectNoteOnToFunction(std::function<void(int, int, int)> function);
100  void connectNoteOffToFunction(std::function<void(int, int, int)> function);
101 
102  virtual void onMIDIMessage(const MIDIMessage &m) override;
103 
104 private:
105  PolySynth *mSynth;
106 
107  RtMidiIn mRtMidiIn;
108  std::vector<std::function<void(int, int, int)>> mNoteOnFunctions;
109  std::vector<std::function<void(int, int, int)>> mNoteOffFunctions;
110 };
111 
112 } // namespace al
113 
114 #endif // AL_SEQUENCERMIDI_H
A PolySynth manages polyphony and rendering of SynthVoice instances.
The SequencerMIDI class connects PolySynth objects to MIDI messages.
virtual void onMIDIMessage(const MIDIMessage &m) override
Called when a MIDI message is received.
Definition: al_App.hpp:23