void Controller_Module::draw ( void ) { Fl_Group::draw(); draw_box(x(),y(),w(),h()); if ( learn_mode() ) { fl_rectf( x(),y(),w(),h(), fl_color_add_alpha( FL_MAGENTA, 50 ) ); } }
int Controller_Module::handle ( int m ) { switch ( m ) { case FL_PUSH: { if ( learn_mode() ) { tooltip( "Now learning control. Move the desired control on your controller" ); //connect_to( &module->control_input[port] ); Port *p = control_output[0].connected_port(); if ( p ) { const char * path = learn_by_number ? p->osc_number_path() : p->osc_path(); DMESSAGE( "Will learn %s", path ); mixer->osc_endpoint->learn( path ); } return 1; } if ( Fl::event_button3() ) { /* context menu */ /* if ( type() != SPATIALIZATION ) */ menu_popup( &menu() ); return 1; } else return Fl_Group::handle( m ); } } return Fl_Group::handle( m ); }
/** main * */ int main ( int argc, char **argv ) { int keys = 0; int mc_offset = 0; snd_seq_event_t ev; int patch = 0; int bank = 0; fprintf( stderr, "lsmi-keyhack" " v" VERSION "\n" ); get_args( argc, argv ); fprintf( stderr, "Registering MIDI port...\n" ); seq = open_client( CLIENT_NAME ); if ( NULL == seq ) { fprintf( stderr, "Error opening alsa sequencer!\n" ); exit( 1 ); } if ( ( port = open_output_port( seq ) ) < 0 ) { fprintf( stderr, "Error opening MIDI output port!\n" ); exit( 1 ); } if ( sub_name ) { snd_seq_addr_t addr; if ( snd_seq_parse_address( seq, &addr, sub_name ) < 0 ) fprintf( stderr, "Couldn't parse address '%s'", sub_name ); else if ( snd_seq_connect_to( seq, port, addr.client, addr.port ) < 0 ) { fprintf( stderr, "Error creating subscription for port %i:%i", addr.client, addr.port ); exit( 1 ); } } fprintf( stderr, "Initializing keyboard...\n" ); if ( -1 == ( fd = open( device, O_RDWR ) ) ) { fprintf( stderr, "Error opening event interface! (%s)\n", strerror( errno ) ); exit( 1 ); } init_keyboard(); set_traps(); update_leds(); fprintf( stderr, "Opening database...\n" ); if ( database == defaultdatabase ) { char *home = getenv( "HOME" ); database = malloc( strlen( home ) + strlen( defaultdatabase ) + 2 ); sprintf( database, "%s/%s", home, defaultdatabase ); } if ( -1 == open_database( database ) ) { fprintf( stderr, "******Key database missing or invalid******\n" "Entering learning mode...\n" "Make sure your \"keyboard\" device is connected!\n" ); learn_mode(); } analyze_map( &keys, &mc_offset ); octave_min = ( mc_offset / 12 ) + 1; octave_max = 9 - ( ( keys - mc_offset ) / 12 ); fprintf( stderr, "%i keys, middle C is %ith from the left, lowest MIDI octave == %i, highest, %i\n", keys, mc_offset + 1, octave_min, octave_max ); fprintf( stderr, "Waiting for events...\n" ); for ( ;; ) { int keyi, newstate; keyi = get_keypress( &newstate ); snd_seq_ev_clear( &ev ); if ( map[keyi].control ) { snd_seq_event_t e; if ( newstate == UP ) continue; switch ( map[keyi].control ) { /* All notes off */ snd_seq_ev_set_controller( &ev, channel, 123, 0 ); send_event( &ev ); snd_seq_ev_clear( &ev ); case CKEY_EXIT: fprintf( stderr, "Exiting...\n" ); if ( close_database( database ) < 0 ) fprintf( stderr, "Error saving database!\n" ); clean_up(); exit( 0 ); case CKEY_MODE: prog_mode = prog_mode + 1 > NUM_PROG_MODES - 1 ? 0 : prog_mode + 1; fprintf( stderr, "Input mode change to %s\n", mode_names[prog_mode] ); update_leds(); break; case CKEY_OCTAVE_DOWN: octave = min( octave - 1, octave_min ); break; case CKEY_OCTAVE_UP: octave = max( octave + 1, octave_max ); break; case CKEY_CHANNEL_DOWN: channel = min( channel - 1, 0 ); break; case CKEY_CHANNEL_UP: channel = max( channel + 1, 15 ); break; case CKEY_PATCH_DOWN: if ( patch == 0 && bank > 0 ) { bank = min( bank - 1, 0 ); patch = 127; snd_seq_ev_set_controller( &e, channel, 0, bank ); send_event( &e ); } else patch = min( patch - 1, 0 ); snd_seq_ev_set_pgmchange( &ev, channel, patch ); break; case CKEY_PATCH_UP: if ( patch == 127 && bank < 127 ) { bank = max( bank + 1, 127 ); patch = 0; snd_seq_ev_set_controller( &e, channel, 0, bank ); send_event( &e ); } else patch = max( patch + 1, 127 ); snd_seq_ev_set_pgmchange( &ev, channel, patch ); break; case CKEY_NUMERIC: { struct timeval tv; gettimeofday( &tv, NULL ); /* Timeout in 5 secs */ if ( tv.tv_sec - timeout.tv_sec >= 5 ) { prog_index = 0; } timeout = tv; if ( prog_index == 0 ) printf( "INPUT %s #: ", mode_names[prog_mode] ); } prog_buf[prog_index++] = 48 + map[keyi].number; printf( "%i", map[keyi].number ); fflush( stdout ); if ( prog_index == 2 && prog_mode == CHANNEL ) { /* FIXME: all notes off->channel */ prog_buf[++prog_index] = '\0'; channel = atoi( prog_buf ); channel = max( channel, 15 ); prog_index = 0; printf( " ENTER\n" ); } else if ( prog_index == 3 ) { prog_buf[++prog_index] = '\0'; switch ( prog_mode ) { case PATCH: patch = atoi( prog_buf ); patch = max( patch, 127 ); snd_seq_ev_set_pgmchange( &ev, channel, patch ); break; case BANK: bank = atoi( prog_buf ); bank = max( bank, 127 ); snd_seq_ev_set_controller( &ev, channel, 0, bank ); break; default: fprintf( stderr, "Internal error!\n" ); } prog_index = 0; printf( " ENTER\n" ); } break; default: fprintf( stderr, "Internal error!\n" ); } send_event( &ev ); continue; } else switch ( map[keyi].ev_type ) { case SND_SEQ_EVENT_CONTROLLER: snd_seq_ev_set_controller( &ev, channel, map[keyi].number, newstate == DOWN ? 127 : 0 ); break; case SND_SEQ_EVENT_NOTE: if ( newstate == DOWN ) snd_seq_ev_set_noteon( &ev, channel, map[keyi].number + ( 12 * octave ), 64 ); else snd_seq_ev_set_noteoff( &ev, channel, map[keyi].number + ( 12 * octave ), 64 ); break; default: fprintf( stderr, "Key has invalid mapping!\n" ); break; } send_event( &ev ); } }