summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/interface/ClientInterface.hpp3
-rw-r--r--src/common/interface/MessageType.hpp120
2 files changed, 123 insertions, 0 deletions
diff --git a/src/common/interface/ClientInterface.hpp b/src/common/interface/ClientInterface.hpp
index 619c48b8..9ec875ac 100644
--- a/src/common/interface/ClientInterface.hpp
+++ b/src/common/interface/ClientInterface.hpp
@@ -28,6 +28,7 @@ namespace Raul { class Path; class URI; }
namespace Ingen {
namespace Shared {
+class MessageType;
/** The (only) interface the engine uses to communicate with clients.
* Purely virtual (except for the destructor).
@@ -55,6 +56,8 @@ public:
virtual void error(const std::string& msg) = 0;
virtual void activity(const Raul::Path& path) = 0;
+
+ virtual void binding(const Raul::Path& path, const MessageType& type) = 0;
};
diff --git a/src/common/interface/MessageType.hpp b/src/common/interface/MessageType.hpp
new file mode 100644
index 00000000..ea6bc726
--- /dev/null
+++ b/src/common/interface/MessageType.hpp
@@ -0,0 +1,120 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net>
+ *
+ * Ingen is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef MESSAGE_TYPE_HPP
+#define MESSAGE_TYPE_HPP
+
+#include <cassert>
+#include <iostream>
+#include <string>
+
+namespace Ingen {
+namespace Shared {
+
+
+/** A type of control message that could be bound to a control port.
+ *
+ * \ingroup interface
+ */
+class MessageType
+{
+public:
+ enum Type {
+ MIDI_PITCH,
+ MIDI_CC,
+ MIDI_RPN,
+ MIDI_NRPN
+ };
+
+ MessageType(Type type, int16_t num)
+ : _type(type)
+ {
+ switch (type) {
+ case MIDI_PITCH:
+ break;
+ case MIDI_CC:
+ assert(num >= 0 && num < 128);
+ _id.midi_cc = num;
+ break;
+ case MIDI_RPN:
+ assert(num >= 0 && num < 16384);
+ _id.midi_pn = num;
+ break;
+ case MIDI_NRPN:
+ assert(num >= 0 && num < 16384);
+ _id.midi_pn = num;
+ break;
+ }
+ }
+
+ inline Type type() const { return _type; }
+ inline int8_t midi_cc_num() const { assert(_type == MIDI_CC); return _id.midi_cc; }
+ inline int8_t midi_rpn_num() const { assert(_type == MIDI_RPN); return _id.midi_pn; }
+ inline int8_t midi_nrpn_num() const { assert(_type == MIDI_NRPN); return _id.midi_pn; }
+
+ inline int num() const {
+ switch (_type) {
+ case MIDI_CC:
+ return _id.midi_cc;
+ case MIDI_RPN:
+ case MIDI_NRPN:
+ return _id.midi_pn;
+ default:
+ return -1;
+ }
+ }
+
+ inline const char* type_uri() const {
+ switch (_type) {
+ case MIDI_PITCH:
+ return "midi:PitchBend";
+ case MIDI_CC:
+ return "midi:Control";
+ case MIDI_RPN:
+ return "midi:RPN";
+ case MIDI_NRPN:
+ return "midi:NRPN";
+ }
+ }
+
+private:
+ union {
+ int8_t midi_cc; ///< Controller number [0..2^7)
+ int16_t midi_pn; ///< RPN or NRPN number [0..2^14)
+ } _id;
+
+ Type _type;
+};
+
+
+} // namespace Shared
+} // namespace Ingen
+
+
+static inline std::ostream& operator<<(std::ostream& os, const Ingen::Shared::MessageType& type)
+{
+ using namespace Ingen::Shared;
+ switch (type.type()) {
+ case MessageType::MIDI_PITCH: return os << "MIDI Pitch Bender";
+ case MessageType::MIDI_CC: return os << "MIDI CC " << type.num();
+ case MessageType::MIDI_RPN: return os << "MIDI RPN " << type.num();
+ case MessageType::MIDI_NRPN: return os << "MIDI NRPN " << type.num();
+ }
+ return os;
+}
+
+#endif // MESSAGE_TYPE_HPP