andrewm@0: /* andrewm@0: TouchKeys: multi-touch musical keyboard control software andrewm@0: Copyright (c) 2013 Andrew McPherson andrewm@0: andrewm@0: This program is free software: you can redistribute it and/or modify andrewm@0: it under the terms of the GNU General Public License as published by andrewm@0: the Free Software Foundation, either version 3 of the License, or andrewm@0: (at your option) any later version. andrewm@0: andrewm@0: This program is distributed in the hope that it will be useful, andrewm@0: but WITHOUT ANY WARRANTY; without even the implied warranty of andrewm@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the andrewm@0: GNU General Public License for more details. andrewm@0: andrewm@0: You should have received a copy of the GNU General Public License andrewm@0: along with this program. If not, see . andrewm@0: andrewm@0: ===================================================================== andrewm@0: andrewm@0: MidiOutputController.h: handles outgoing MIDI messages and manages output andrewm@0: ports; uses Juce MIDI library functions. andrewm@0: */ andrewm@0: andrewm@0: #ifndef MIDI_OUTPUT_CONTROLLER_H andrewm@0: #define MIDI_OUTPUT_CONTROLLER_H andrewm@0: andrewm@0: #include andrewm@0: #include "MidiInputController.h" andrewm@0: andrewm@0: const juce::String kMidiVirtualOutputName = "TouchKeys"; andrewm@0: andrewm@0: using namespace std; andrewm@0: andrewm@0: class MidiOutputController { andrewm@0: private: andrewm@0: struct MidiOutputControllerRecord { andrewm@0: int portNumber; andrewm@0: MidiOutput *output; andrewm@0: }; andrewm@0: andrewm@0: public: andrewm@0: enum { andrewm@0: kMidiVirtualOutputPortNumber = -2, andrewm@0: kMidiOutputNotOpen = -1 andrewm@0: }; andrewm@0: andrewm@0: // Constructor andrewm@0: MidiOutputController(); andrewm@0: andrewm@0: // Query available devices andrewm@0: vector > availableMidiDevices(); andrewm@0: andrewm@0: // Methods to connect/disconnect from a target port andrewm@0: bool enablePort(int identifier, int deviceNumber); andrewm@20: #ifndef JUCE_WINDOWS andrewm@0: bool enableVirtualPort(int identifier, const char *name); andrewm@20: #endif andrewm@0: void disablePort(int identifier); andrewm@0: void disableAllPorts(); andrewm@0: andrewm@0: int enabledPort(int identifier); andrewm@0: std::vector > enabledPorts(); andrewm@0: andrewm@41: // Get the name of a particular port index andrewm@41: String deviceName(int portNumber); andrewm@41: andrewm@41: // Find the index of a device with a given name; return -1 if not found andrewm@41: int indexOfDeviceNamed(String const& name); andrewm@41: andrewm@0: // Send MIDI messages andrewm@0: void sendNoteOn(int port, unsigned char channel, unsigned char note, unsigned char velocity); andrewm@0: void sendNoteOff(int port, unsigned char channel, unsigned char note, unsigned char velocity = 64); andrewm@0: void sendControlChange(int port, unsigned char channel, unsigned char control, unsigned char value); andrewm@0: void sendProgramChange(int port, unsigned char channel, unsigned char value); andrewm@0: void sendAftertouchChannel(int port, unsigned char channel, unsigned char value); andrewm@0: void sendAftertouchPoly(int port, unsigned char channel, unsigned char note, unsigned char value); andrewm@0: void sendPitchWheel(int port, unsigned char channel, unsigned int value); andrewm@0: void sendReset(int port); andrewm@0: andrewm@0: // Generic pre-formed messages andrewm@0: void sendMessage(int port, const MidiMessage& message); andrewm@0: andrewm@0: // Destructor andrewm@0: ~MidiOutputController() { disableAllPorts(); } andrewm@0: andrewm@0: private: andrewm@0: std::map activePorts_; // Destinations for MIDI data andrewm@0: }; andrewm@0: andrewm@0: #endif /* MIDI_OUTPUT_CONTROLLER_H */