Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 00020 #include "RadioDrumInput.h" 00021 #include "../common_source.h" 00022 00023 00024 #ifdef MARSYAS_MIDIIO 00025 #include "RtMidi.h" 00026 #endif 00027 00028 #include <cstddef> 00029 00030 using namespace std; 00031 using namespace Marsyas; 00032 00033 RadioDrumInput::RadioDrumInput(mrs_string name):MarSystem("RadioDrumInput",name) 00034 { 00035 initMidi = false; 00036 #ifdef MARSYAS_MIDIIO 00037 rdin = NULL; 00038 #endif 00039 addControls(); 00040 } 00041 00042 RadioDrumInput::RadioDrumInput(const RadioDrumInput& a): MarSystem(a) 00043 { 00044 rx_ = getctrl("mrs_natural/rightstickx"); 00045 ry_ = getctrl("mrs_natural/rightsticky"); 00046 rz_ = getctrl("mrs_natural/rightstickz"); 00047 lx_ = getctrl("mrs_natural/leftstickx"); 00048 ly_ = getctrl("mrs_natural/leftsticky"); 00049 lz_ = getctrl("mrs_natural/leftstickz"); 00050 } 00051 00052 RadioDrumInput::~RadioDrumInput() 00053 { 00054 #ifdef MARSYAS_MIDIIO 00055 delete rdin; 00056 #endif 00057 } 00058 00059 MarSystem* RadioDrumInput::clone() const 00060 { 00061 return new RadioDrumInput(*this); 00062 } 00063 00064 void RadioDrumInput::addControls() 00065 { 00066 addctrl("mrs_natural/port", 0); 00067 addctrl("mrs_bool/initmidi", false); 00068 setctrlState("mrs_bool/initmidi", true); 00069 addctrl("mrs_natural/rightstickx", 0, rx_); 00070 addctrl("mrs_natural/rightsticky", 0, ry_); 00071 addctrl("mrs_natural/rightstickz", 0, rz_); 00072 addctrl("mrs_natural/leftstickx", 0, lx_); 00073 addctrl("mrs_natural/leftsticky", 0, ly_); 00074 addctrl("mrs_natural/leftstickz", 0, lz_); 00075 } 00076 00077 void RadioDrumInput::myUpdate(MarControlPtr sender) 00078 { 00079 MRSDIAG("RadioDrumInput.cpp - RadioDrumInput:myUpdate"); 00080 MarSystem::myUpdate(sender); 00081 00082 #ifdef MARSYAS_MIDIIO 00083 rdin = NULL; 00084 00085 initMidi= getctrl("mrs_bool/initmidi")->to<mrs_bool>(); 00086 00087 if (!initMidi) { 00088 try { 00089 rdin = new RtMidiIn(); 00090 } 00091 catch (RtError &error) { 00092 error.printMessage(); 00093 return; 00094 } 00095 rdin->setCallback(&RadioDrumInput::mycallback, this); 00096 rdin->ignoreTypes(false, false, false); 00097 setctrl("mrs_bool/initmidi", false); 00098 00099 try { 00100 rdin->openPort(getctrl("mrs_natural/port")->to<mrs_natural>()); 00101 } 00102 catch (RtError &error) 00103 { 00104 error.printMessage(); 00105 return; 00106 } 00107 initMidi = !initMidi; 00108 } 00109 #endif 00110 } 00111 00112 /* 00113 From the Radio Drum Manual 00114 ----------------------------------------- 00115 00116 MIDI COMMAND (THREE BYTES) 00117 BYTE1 BYTE2 BYTE3** 00118 trigger from stick 1 & whack strength A0 1 WHACK 00119 & X1 A0 15 X1 00120 & Y1 A0 16 Y1 00121 trigger from stick 2 & whack strength A0 2 WHACK 00122 & X2 A0 17 X2 00123 & Y2 A0 18 Y2 00124 trigger from B15+ button A0 3 1 00125 down trigger from B14- foot switch A0 3 2 00126 up trigger from B14- foot switch A0 3 3 00127 down trigger from B15- foot switch A0 3 4 00128 up trigger from B15- foot switch A0 3 5 00129 pot 1 current value A0 4 POT1 00130 pot 2 current value A0 5 POT2 00131 pot 3 current value A0 6 POT3 00132 pot 4 current value A0 7 POT4 00133 stick 1 x current position A0 8 X1 00134 stick 1 y current position A0 9 Y1 00135 stick 1 z current position A0 10 Z1 00136 stick 2 x current position A0 11 X2 00137 stick 2 y current position A0 12 Y2 00138 stick 2 z current position A0 13 Z2 00139 00140 All data in BYTE3 is encoded in the standard midi range 0-127 00141 00142 */ 00143 void RadioDrumInput::mycallback(double deltatime, std::vector< unsigned char > * message, void *userData) 00144 { 00145 // FIXME Unused parameter 00146 (void) deltatime; 00147 size_t nBytes = 0; 00148 nBytes = message->size(); 00149 00150 RadioDrumInput* mythis = (RadioDrumInput*) userData; 00151 00152 // fix this to make more sense with specific radio drum input 00153 if (nBytes == 3) 00154 { 00155 00156 // 160 is to detect poly pressure on channel 1 0xA0 00157 if ( message->at(0) == 160) { 00158 if(message->at(1) == 8) 00159 mythis->rightstickx = message->at(2); 00160 else if ( message->at(1)==9) 00161 mythis->rightsticky = message->at(2); 00162 else if ( message->at(1)==10) 00163 mythis->rightstickz = message->at(2); 00164 else if ( message->at(1)==11) 00165 mythis->leftstickx = message->at(2); 00166 else if ( message->at(1)==12) 00167 mythis->leftsticky = message->at(2); 00168 else if ( message->at(1)==13) 00169 mythis->leftstickz = message->at(2); 00170 } 00171 00172 } 00173 } 00174 00175 void RadioDrumInput::myProcess(realvec& in, realvec& out) 00176 { 00177 mrs_natural o,t; 00178 // just pass data through 00179 for (o=0; o < inObservations_; o++) 00180 for (t = 0; t < inSamples_; t++) 00181 { 00182 out(o,t) = in(o,t); 00183 } 00184 00185 rx_->setValue((mrs_natural)rightstickx, NOUPDATE); 00186 ry_->setValue((mrs_natural)rightsticky, NOUPDATE); 00187 rz_->setValue((mrs_natural)rightstickz, NOUPDATE); 00188 lx_->setValue((mrs_natural)leftstickx, NOUPDATE); 00189 ly_->setValue((mrs_natural)leftsticky, NOUPDATE); 00190 lz_->setValue((mrs_natural)leftstickz, NOUPDATE); 00191 00192 }