Marsyas  0.5.0-beta1
/Users/jleben/code/marsyas/src/marsyas/marsystems/Esitar.cpp
Go to the documentation of this file.
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 #include "../common_source.h"
00020 #include "Esitar.h"
00021 
00022 #ifdef MARSYAS_MIDIIO
00023 #include "RtMidi.h"
00024 #endif
00025 
00026 
00027 using std::ostringstream;
00028 using namespace Marsyas;
00029 
00030 Esitar::Esitar(mrs_string name):MarSystem("Esitar",name)
00031 {
00032   //type_ = "Esitar";
00033   //name_ = name;
00034 
00035 #ifdef MARSYAS_MIDIIO
00036   midiin = NULL;
00037 #endif
00038 }
00039 
00040 
00041 Esitar::~Esitar()
00042 {
00043 #ifdef MARSYAS_MIDIIO
00044   delete midiin;
00045 #endif
00046 }
00047 
00048 
00049 MarSystem*
00050 Esitar::clone() const
00051 {
00052   return new Esitar(*this);
00053 }
00054 
00055 void
00056 Esitar::myUpdate(MarControlPtr sender)
00057 {
00058   MRSDIAG("Esitar.cpp - Esitar:myUpdate");
00059 
00060 //  setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples"));
00061 //   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations"));
00062 //   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00063 //   setctrl("mrs_string/onObsNames", getctrl("mrs_string/inObsNames"));
00064   MarSystem::myUpdate(sender);
00065 
00066 #ifdef MARSYAS_MIDIIO
00067   try {
00068     midiin = new RtMidiIn();
00069   }
00070   catch (RtError &error) {
00071     error.printMessage();
00072     return;
00073   }
00074 
00075   try {
00076     midiin->openPort(0);
00077   }
00078   catch (RtError &error)
00079   {
00080     error.printMessage();
00081     return;
00082   }
00083   midiin->setCallback(&Esitar::mycallback, this);
00084   midiin->ignoreTypes(false, false, false);
00085 #endif
00086 }
00087 
00088 
00089 void
00090 Esitar::mycallback(double deltatime, std::vector< unsigned char > * message, void *userData)
00091 {
00092   // FIXME Unused parameter
00093   (void) deltatime;
00094   size_t nBytes = 0;
00095   nBytes = message->size();
00096 
00097   Esitar* mythis = (Esitar*) userData;
00098 
00099 
00100   if (nBytes > 0)
00101   {
00102     if (nBytes > 2)
00103     {
00104       mythis->byte3 = message->at(2);
00105       mythis->byte2 = message->at(1);
00106       mythis->type = message->at(0);
00107     }
00108 
00109     // thumb
00110     if ((mythis->type == 176)&&(mythis->byte2 == 1))
00111     {
00112       mythis->thumb = mythis->byte3;
00113     }
00114 
00115     // fret
00116     if ((mythis->type == 176)&&(mythis->byte2 == 2))
00117     {
00118       mythis->fret = mythis->byte3;
00119     }
00120 
00121     // headx
00122     if ((mythis->type == 176)&&(mythis->byte2 == 6))
00123     {
00124       mythis->headx = mythis->byte3;
00125     }
00126 
00127     // heady
00128     if ((mythis->type == 176)&&(mythis->byte2 == 8))
00129     {
00130       mythis->heady = mythis->byte3;
00131     }
00132 
00133     // headz
00134     if ((mythis->type == 176)&&(mythis->byte2 == 10))
00135     {
00136       mythis->headz = mythis->byte3;
00137     }
00138 
00139     // pot1
00140     if ((mythis->type == 176)&&(mythis->byte2 == 7))
00141     {
00142       mythis->pot1 = mythis->byte3;
00143     }
00144 
00145     // pot2
00146     if ((mythis->type == 176)&&(mythis->byte2 == 9))
00147     {
00148       mythis->pot2 = mythis->byte3;
00149     }
00150 
00151     // switch1
00152     if ((mythis->type == 144)&&(mythis->byte2 == 1))
00153     {
00154       mythis->switch1 = mythis->byte3;
00155     }
00156 
00157     // switch2
00158     if ((mythis->type == 144)&&(mythis->byte2 == 2))
00159     {
00160       mythis->switch2 = mythis->byte3;
00161     }
00162 
00163     // switch3
00164     if ((mythis->type == 144)&&(mythis->byte2 == 3))
00165     {
00166       mythis->switch3 = mythis->byte3;
00167     }
00168 
00169     // switch4
00170     if ((mythis->type == 144)&&(mythis->byte2 == 4))
00171     {
00172       mythis->switch4 = mythis->byte3;
00173     }
00174 
00175     // switch5
00176     if ((mythis->type == 144)&&(mythis->byte2 == 5))
00177     {
00178       mythis->switch5 = mythis->byte3;
00179     }
00180 
00181     // switch6
00182     if ((mythis->type == 144)&&(mythis->byte2 == 6))
00183     {
00184       mythis->switch6 = mythis->byte3;
00185     }
00186 
00187     // switch7
00188     if ((mythis->type == 144)&&(mythis->byte2 == 7))
00189     {
00190       mythis->switch7 = mythis->byte3;
00191     }
00192 
00193     // switch8
00194     if ((mythis->type == 144)&&(mythis->byte2 == 8))
00195     {
00196       mythis->switch8 = mythis->byte3;
00197     }
00198 
00199     // switch9
00200     if ((mythis->type == 144)&&(mythis->byte2 == 9))
00201     {
00202       mythis->switch9 = mythis->byte3;
00203     }
00204 
00205     // switch10
00206     if ((mythis->type == 144)&&(mythis->byte2 == 10))
00207     {
00208       mythis->switch10 = mythis->byte3;
00209     }
00210 
00211   }
00212 }
00213 
00214 void
00215 Esitar::myProcess(realvec& in, realvec& out)
00216 {
00217   mrs_natural o,t;
00218   //checkFlow(in,out);
00219 
00220   for (o=0; o < inObservations_; o++)
00221     for (t = 0; t < inSamples_; t++)
00222     {
00223       out(o,t) =  in(o,t);
00224     }
00225 }
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233