#include #include #include #include #include "alsamidi.h" using namespace std; const char * mididrum []= { "Bass Drum 2", "Bass Drum 1", "Side Stick", "Snare Drum 1", "Hand Clap", "Snare Drum 2", "Low Tom 2", "Closed Hi Hat", "Low Tom 1", "Pedal Hi Hat", "Mid Tom 2", "Open Hi Hat", "Mid Tom 1", "High Tom 2", "Crash Cymbal 1", "Hi Tom 1", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal", "Cowbell", "Crash Cymbal 2", "Vibra Slap", "Ride Cymbal", "High Bongo", "Low Bongo", "Mute High Conga", "Open High Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo", "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro", "Long Guiro", "Claves", "High Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica", "Mute Triangle", "Open Triangle", NULL }; /** * Application class */ class Application { public: Gtk::Window * window; Gtk::ComboBox * combobox[6]; Gtk::ComboBox * combobox_midi_channel; Gtk::Label * label_status; Glib::Thread * thread; bool quit_requested; bool running; int channel; int drum_notes [6]; libusb_device_handle *dev_handle; libusb_context *ctx; /** * Application constructor * interface intilialization goes here */ Application() { cout<<"[Application]"< glade; glade=Gtk::Builder::create_from_file("/usr/share/drumroll/interface.glade"); glade->get_widget("winDrumroll",window); glade->get_widget("combobox1",combobox[0]); glade->get_widget("combobox2",combobox[1]); glade->get_widget("combobox3",combobox[2]); glade->get_widget("combobox4",combobox[3]); glade->get_widget("combobox5",combobox[4]); glade->get_widget("combobox6",combobox[5]); glade->get_widget("combobox7",combobox_midi_channel); glade->get_widget("label9",label_status); window->show_all(); label_status->set_text("loading..."); //filling instruments combos Gtk::TreeModelColumn name_instrument; Gtk::TreeModelColumn value_instrument; Gtk::TreeModel::ColumnRecord cr; cr.add(name_instrument); cr.add(value_instrument); Glib::RefPtr store; store=Gtk::ListStore::create(cr); int n = 0; int drum_offset=35; while(mididrum[n]!=NULL) { cout<<"Midi instrument:"< "<<(drum_offset+n)<append()); row.set_value(0,mididrum[n]); row.set_value(1,drum_offset+n); n++; } for(n=0;n<6;n++) { combobox[n]->set_model(store); combobox[n]->pack_start(name_instrument); combobox[n]->signal_changed().connect(sigc::mem_fun(*this,&Application::on_combobox_changed)); combobox[n]->set_active(n); } //filling midi channel combo Gtk::TreeModelColumn channel; Gtk::TreeModel::ColumnRecord channel_cr; channel_cr.add(channel); Glib::RefPtr channel_store; channel_store=Gtk::ListStore::create(channel_cr); combobox_midi_channel->set_model(channel_store); combobox_midi_channel->pack_start(channel); combobox_midi_channel->signal_changed().connect(sigc::mem_fun(*this,&Application::on_combobox_midi_changed)); for(n=0;n<16;n++) { Gtk::TreeModel::Row row= *(channel_store->append()); row.set_value(0,n+1); } //Using channel 10 //as recommended by General Midi combobox_midi_channel->set_active(9); //turning thread on thread = Glib::Thread::create(sigc::mem_fun(*this, &Application::run), true); } /** * Destructor */ ~Application() { cout<<"[~Application]"<join(); } /** * instrument combo changed */ void on_combobox_changed() { cout<<"[on_combobox_changed]"<get_active(); if(iter) { Gtk::TreeModel::Row row = *iter; row.get_value(0,name); row.get_value(1,value); cout <<"ComboBox"<<(n+1)<<":"<get_active(); if(iter) { Gtk::TreeModel::Row row = *iter; row.get_value(0,this->channel); this->channel--; cout <<"MidiChannel:"<channel<set_text("ready"); running=true; while(!quit_requested) { //res=libusb_interrupt_transfer(dev_handle,(1 | LIBUSB_ENDPOINT_IN),buffer,8,&length,1000); res=libusb_bulk_transfer(dev_handle,(1 | LIBUSB_ENDPOINT_IN),buffer,8,&length,500); if(res==0) { /* for(int n=0;n0) { if(buffer[0]==1) alsamidi_send_event(drum_notes[0], ALSAMIDI_MAX_VELOCITY,channel); if(buffer[0]==2) alsamidi_send_event(drum_notes[1], ALSAMIDI_MAX_VELOCITY,channel); if(buffer[0]==4) alsamidi_send_event(drum_notes[2], ALSAMIDI_MAX_VELOCITY,channel); if(buffer[0]==8) alsamidi_send_event(drum_notes[3], ALSAMIDI_MAX_VELOCITY,channel); if(buffer[0]==16) alsamidi_send_event(drum_notes[4], ALSAMIDI_MAX_VELOCITY,channel); if(buffer[0]==32) alsamidi_send_event(drum_notes[5], ALSAMIDI_MAX_VELOCITY,channel); } } else { switch(res) { case LIBUSB_ERROR_TIMEOUT: //cout<<"* interrupt timeout"<set_text("disconnecting"); cout<<"[run] exit"<