annotate Source/TouchKeys/MidiOutputController.h @ 56:b4a2d2ae43cf tip

merge
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Fri, 23 Nov 2018 15:48:14 +0000
parents 85577160a0d4
children
rev   line source
andrewm@0 1 /*
andrewm@0 2 TouchKeys: multi-touch musical keyboard control software
andrewm@0 3 Copyright (c) 2013 Andrew McPherson
andrewm@0 4
andrewm@0 5 This program is free software: you can redistribute it and/or modify
andrewm@0 6 it under the terms of the GNU General Public License as published by
andrewm@0 7 the Free Software Foundation, either version 3 of the License, or
andrewm@0 8 (at your option) any later version.
andrewm@0 9
andrewm@0 10 This program is distributed in the hope that it will be useful,
andrewm@0 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
andrewm@0 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
andrewm@0 13 GNU General Public License for more details.
andrewm@0 14
andrewm@0 15 You should have received a copy of the GNU General Public License
andrewm@0 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
andrewm@0 17
andrewm@0 18 =====================================================================
andrewm@0 19
andrewm@0 20 MidiOutputController.h: handles outgoing MIDI messages and manages output
andrewm@0 21 ports; uses Juce MIDI library functions.
andrewm@0 22 */
andrewm@0 23
andrewm@0 24 #ifndef MIDI_OUTPUT_CONTROLLER_H
andrewm@0 25 #define MIDI_OUTPUT_CONTROLLER_H
andrewm@0 26
andrewm@0 27 #include <map>
andrewm@0 28 #include "MidiInputController.h"
andrewm@0 29
andrewm@0 30 const juce::String kMidiVirtualOutputName = "TouchKeys";
andrewm@0 31
andrewm@0 32 using namespace std;
andrewm@0 33
andrewm@0 34 class MidiOutputController {
andrewm@0 35 private:
andrewm@0 36 struct MidiOutputControllerRecord {
andrewm@0 37 int portNumber;
andrewm@0 38 MidiOutput *output;
andrewm@0 39 };
andrewm@0 40
andrewm@0 41 public:
andrewm@0 42 enum {
andrewm@0 43 kMidiVirtualOutputPortNumber = -2,
andrewm@0 44 kMidiOutputNotOpen = -1
andrewm@0 45 };
andrewm@0 46
andrewm@0 47 // Constructor
andrewm@0 48 MidiOutputController();
andrewm@0 49
andrewm@0 50 // Query available devices
andrewm@0 51 vector<pair<int, string> > availableMidiDevices();
andrewm@0 52
andrewm@0 53 // Methods to connect/disconnect from a target port
andrewm@0 54 bool enablePort(int identifier, int deviceNumber);
andrewm@20 55 #ifndef JUCE_WINDOWS
andrewm@0 56 bool enableVirtualPort(int identifier, const char *name);
andrewm@20 57 #endif
andrewm@0 58 void disablePort(int identifier);
andrewm@0 59 void disableAllPorts();
andrewm@0 60
andrewm@0 61 int enabledPort(int identifier);
andrewm@0 62 std::vector<std::pair<int, int> > enabledPorts();
andrewm@0 63
andrewm@41 64 // Get the name of a particular port index
andrewm@41 65 String deviceName(int portNumber);
andrewm@41 66
andrewm@41 67 // Find the index of a device with a given name; return -1 if not found
andrewm@41 68 int indexOfDeviceNamed(String const& name);
andrewm@41 69
andrewm@0 70 // Send MIDI messages
andrewm@0 71 void sendNoteOn(int port, unsigned char channel, unsigned char note, unsigned char velocity);
andrewm@0 72 void sendNoteOff(int port, unsigned char channel, unsigned char note, unsigned char velocity = 64);
andrewm@0 73 void sendControlChange(int port, unsigned char channel, unsigned char control, unsigned char value);
andrewm@0 74 void sendProgramChange(int port, unsigned char channel, unsigned char value);
andrewm@0 75 void sendAftertouchChannel(int port, unsigned char channel, unsigned char value);
andrewm@0 76 void sendAftertouchPoly(int port, unsigned char channel, unsigned char note, unsigned char value);
andrewm@0 77 void sendPitchWheel(int port, unsigned char channel, unsigned int value);
andrewm@0 78 void sendReset(int port);
andrewm@0 79
andrewm@0 80 // Generic pre-formed messages
andrewm@0 81 void sendMessage(int port, const MidiMessage& message);
andrewm@0 82
andrewm@0 83 // Destructor
andrewm@0 84 ~MidiOutputController() { disableAllPorts(); }
andrewm@0 85
andrewm@0 86 private:
andrewm@0 87 std::map<int, MidiOutputControllerRecord> activePorts_; // Destinations for MIDI data
andrewm@0 88 };
andrewm@0 89
andrewm@0 90 #endif /* MIDI_OUTPUT_CONTROLLER_H */