void JVlibForm::connect_port() { if (seq && strlen(SEQ_dev)) { // create_source_port snd_seq_port_info_t *pinfo; snd_seq_port_info_alloca(&pinfo); // the first created port is 0 anyway, but let's make sure ... snd_seq_port_info_set_port(pinfo, 0); snd_seq_port_info_set_port_specified(pinfo, 1); snd_seq_port_info_set_name(pinfo, "midi_player"); snd_seq_port_info_set_capability(pinfo, 0); snd_seq_port_info_set_type(pinfo, SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION); int err = snd_seq_create_port(seq, pinfo); check_snd("create port", err); ports = (snd_seq_addr_t *)realloc(ports, sizeof(snd_seq_addr_t)); err = snd_seq_parse_address(seq, &ports[0], SEQ_dev); if (err < 0) { QMessageBox::critical(this, "MIDI Player", QString("Invalid port%1\n%2") .arg(SEQ_dev) .arg(snd_strerror(err))); return; } err = snd_seq_connect_to(seq, 0, ports[0].client, ports[0].port); if (err < 0 && err!= -16) QMessageBox::critical(this, "MIDI Player", QString("%4 Cannot connect to port %1:%2 - %3") .arg(ports[0].client) .arg(ports[0].port) .arg(strerror(errno)) .arg(err)); } } // end connect_port
/* parses one or more port addresses from the string */ static void parse_ports(const char *arg) { char *buf, *s, *port_name; int err; /* make a copy of the string because we're going to modify it */ buf = strdup(arg); check_mem(buf); for (port_name = s = buf; s; port_name = s + 1) { /* Assume that ports are separated by commas. We don't use * spaces because those are valid in client names. */ s = strchr(port_name, ','); if (s) *s = '\0'; ++port_count; ports = realloc(ports, port_count * sizeof(snd_seq_addr_t)); check_mem(ports); err = snd_seq_parse_address(seq, &ports[port_count - 1], port_name); if (err < 0) fatal("Invalid port %s - %s", port_name, snd_strerror(err)); } free(buf); }
void JVlibForm::disconnect_port() { if (seq && strlen(SEQ_dev)) { int err; ports = (snd_seq_addr_t *)realloc(ports, sizeof(snd_seq_addr_t)); err = snd_seq_parse_address(seq, &ports[0], SEQ_dev); if (err < 0) { QMessageBox::critical(this, "MIDI Player", QString("Invalid port%1\n%2") .arg(SEQ_dev) .arg(snd_strerror(err))); return; } // stop_sound(); err = snd_seq_disconnect_to(seq, 0, ports[0].client, ports[0].port); } // end if seq } // end disconnect_port
/* Remote device name is saved after first call (or rather the pointer to it, * so the actual string must not be deallocated); subsequent calls may use * NULL as the remote_device. */ int midi_connect(int port, const char *remote_device) { snd_seq_port_subscribe_t *sub; snd_seq_addr_t my_addr; snd_seq_addr_t remote_addr; static const char *saved_remote_device[MAX_PORTS] = { 0 }; if (port >= MAX_PORTS) return -1; if (remote_device) saved_remote_device[port] = remote_device; else if (!saved_remote_device[port]) /* Set to "" if first call does not intitialize it to remote_device */ saved_remote_device[port] = ""; dprintf("Client address %d:%d\n", client, port); snd_seq_port_subscribe_alloca(&sub); /* My address */ my_addr.client = client; my_addr.port = ports[port]; /* Other devices address */ if (snd_seq_parse_address(seq, &remote_addr, saved_remote_device[port]) < 0) { dprintf("Can't locate destination device %s\n", saved_remote_device[port]); return -1; } /* We always attempt to set up subscription in both directions, regardless * of which error occurs when setting up the first direction. */ /* Set up sender and destination in subscription. */ snd_seq_port_subscribe_set_sender(sub, &my_addr); snd_seq_port_subscribe_set_dest(sub, &remote_addr); int res = subscribe(sub); /* And now, connection in other direction. */ snd_seq_port_subscribe_set_sender(sub, &remote_addr); snd_seq_port_subscribe_set_dest(sub, &my_addr); int res2 = subscribe(sub); if (res == 0) res = res2; /* if first subscribe() had no error */ return res; }
void MidiAlsaSeq::subscribeWritablePort( MidiPort * _port, const QString & _dest, bool _subscribe ) { if( !m_portIDs.contains( _port ) ) { return; } const int pid = m_portIDs[_port][1] < 0 ? m_portIDs[_port][0] : m_portIDs[_port][1]; if( pid < 0 ) { return; } m_seqMutex.lock(); snd_seq_addr_t dest; if( snd_seq_parse_address( m_seqHandle, &dest, _dest.section( ' ', 0, 0 ).toLatin1().constData() ) ) { fprintf( stderr, "error parsing dest-address!\n" ); m_seqMutex.unlock(); return; } snd_seq_port_info_t * port_info; snd_seq_port_info_malloc( &port_info ); snd_seq_get_port_info( m_seqHandle, pid, port_info ); const snd_seq_addr_t * sender = snd_seq_port_info_get_addr( port_info ); snd_seq_port_subscribe_t * subs; snd_seq_port_subscribe_malloc( &subs ); snd_seq_port_subscribe_set_sender( subs, sender ); snd_seq_port_subscribe_set_dest( subs, &dest ); if( _subscribe ) { snd_seq_subscribe_port( m_seqHandle, subs ); } else { snd_seq_unsubscribe_port( m_seqHandle, subs ); } snd_seq_port_subscribe_free( subs ); snd_seq_port_info_free( port_info ); m_seqMutex.unlock(); }
/** main * */ int main ( int argc, char **argv ) { fprintf( stderr, "lsmi-joystick" " 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 ); } } if ( daemonize ) { printf( "Running as daemon...\n" ); if ( fork() ) exit( 0 ); else { fclose( stdout ); fclose( stderr ); } } fprintf( stderr, "Initializing joystick...\n" ); if ( -1 == ( jfd = open( joydevice, O_RDONLY ) ) ) { fprintf( stderr, "Error opening event interface! (%s)\n", strerror( errno ) ); clean_up(); exit(1); } set_traps(); fprintf( stderr, "Waiting for events...\n" ); for ( ;; ) { struct js_event e; snd_seq_event_t ev; static int b1; static int b2; read (jfd, &e, sizeof(struct js_event)); snd_seq_ev_clear( &ev ); switch (e.type) { case JS_EVENT_BUTTON: switch (e.number) { case 0: if(e.value) b1 = 1; else { b1 = 0; snd_seq_ev_set_pitchbend( &ev, channel, 0 ); send_event( &ev ); } break; case 1: if (e.value) b2 = 1; else { b2 = 0; snd_seq_ev_set_controller( &ev, channel, 1, 0 ); send_event( &ev ); snd_seq_ev_set_controller( &ev, channel, 33, 0 ); send_event( &ev ); } break; } break; case JS_EVENT_AXIS: if ( e.number == 1 && ( b1 || nohold ) ) { snd_seq_ev_set_pitchbend( &ev, channel, 0 - (int)((e.value) * ((float)8191/32767) )); send_event( &ev ); } else if ( ( e.number == 1 && b2 ) || ( e.number == 0 && ( ( b1 && b2 ) || nohold ) ) ) { int fine = (int)((0 - e.value) + 32767) * ((float)16383/65534); int course = fine >> 7; fine &= 0x7F; snd_seq_ev_set_controller( &ev, channel, 1, course ); send_event( &ev ); snd_seq_ev_set_controller( &ev, channel, 33, fine ); send_event( &ev ); } break; default: break; } }
/** main * */ int main ( int argc, char **argv ) { snd_seq_event_t ev; struct input_event iev; snd_seq_addr_t addr; fprintf( stderr, "lsmi-mouse" " v" VERSION "\n" ); get_args( argc, argv ); fprintf( stderr, "Initializing mouse interface...\n" ); if ( -1 == ( fd = open( device, O_RDONLY ) ) ) { fprintf( stderr, "Error opening event interface! (%s)\n", strerror( errno ) ); exit(1); } init_mouse(); fprintf( stderr, "Registering MIDI port...\n" ); seq = open_client( CLIENT_NAME ); port = open_output_port( seq ); if ( sub_name ) { 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 ); } } if ( daemonize ) { printf( "Running as daemon...\n" ); if ( fork() ) exit( 0 ); else { fclose( stdout ); fclose( stderr ); } } set_traps(); fprintf( stderr, "Waiting for packets...\n" ); for ( ;; ) { int i; read( fd, &iev, sizeof( iev ) ); if ( iev.type != EV_KEY ) continue; switch ( iev.code ) { case BTN_LEFT: i = 0; break; case BTN_MIDDLE: i = 1; break; case BTN_RIGHT: i = 2; break; break; default: continue; break; } snd_seq_ev_clear( &ev ); switch ( ev.type = map[i].ev_type ) { case SND_SEQ_EVENT_CONTROLLER: snd_seq_ev_set_controller( &ev, map[i].channel, map[i].number, iev.value == DOWN ? 127 : 0 ); break; case SND_SEQ_EVENT_NOTEON: snd_seq_ev_set_noteon( &ev, map[i].channel, map[i].number, iev.value == DOWN ? 127 : 0 ); break; default: fprintf( stderr, "Internal error: invalid mapping!\n" ); continue; break; } send_event( &ev ); } }
int main(int argc, char *argv[]) { int getopt_return; int option_index; int valid; snd_seq_t *seq_handle; int out_port; snd_seq_addr_t seq_addr; snd_seq_event_t ev; valid = 0; while (((getopt_return = getopt_long(argc, argv, "ha:p:c:b:n:o:", options, &option_index)) >= 0) && (valid < 2)) { switch(getopt_return) { case 'a': valid++; if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) { fprintf(stderr, "Error opening ALSA sequencer.\n"); exit(1); } snd_seq_set_client_name(seq_handle, "MidiSend"); if ((out_port = snd_seq_create_simple_port(seq_handle, "MidiSend", SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ, SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { fprintf(stderr, "Error creating sequencer port.\n"); exit(1); } snd_seq_parse_address(seq_handle, &seq_addr, optarg); snd_seq_connect_to(seq_handle, out_port, seq_addr.client, seq_addr.port); snd_seq_ev_clear(&ev); snd_seq_ev_set_subs(&ev); snd_seq_ev_set_direct(&ev); snd_seq_ev_set_source(&ev, out_port); break; case 'p': if (valid) { valid++; if (argc < 6) { fprintf(stderr, "\nMissing parameter(s): midisend --program <ch> <prg>\n\n"); } else { ev.data.control.channel = atoi(optarg); ev.type = SND_SEQ_EVENT_PGMCHANGE; ev.data.control.value = atoi(argv[optind]); } } break; case 'c': if (valid) { valid++; if (argc < 7) { fprintf(stderr, "\nMissing parameter(s): midisend --control <ch> <ctrl> <val>\n\n"); } else { ev.data.control.channel = atoi(optarg); ev.type = SND_SEQ_EVENT_CONTROLLER; ev.data.control.param = atoi(argv[optind]); ev.data.control.value = atoi(argv[optind + 1]); } } break; case 'b': if (valid) { valid++; if (argc < 6) { fprintf(stderr, "\nMissing parameter(s): midisend --bend <ch> <val>\n\n"); } else { ev.data.control.channel = atoi(optarg); ev.type = SND_SEQ_EVENT_PITCHBEND; ev.data.control.value = atoi(argv[optind]) - 8192; } } break; case 'n': if (valid) { valid++; if (argc < 8) { fprintf(stderr, "\nMissing parameter(s): midisend --note <ch> <on> <num> <vel>\n\n"); } else { ev.data.control.channel = atoi(optarg); ev.type = (atoi(argv[optind])) ? SND_SEQ_EVENT_NOTEON : SND_SEQ_EVENT_NOTEOFF; ev.data.note.note = atoi(argv[optind + 1]); ev.data.note.velocity = atoi(argv[optind + 2]); } } break; case 'o': if (valid) { valid++; if (argc < 5) { fprintf(stderr, "\nMissing parameter(s): midisend --off <ch>\n\n"); } else { ev.data.control.channel = atoi(optarg); ev.type = SND_SEQ_EVENT_CONTROLLER; ev.data.control.param = MIDI_CTL_ALL_NOTES_OFF; ev.data.control.value = 0; } } break; case 'h': valid = 3; printf("\nMidiSend 0.0.1\nWritten by Matthias Nagorni\n"); printf("(c)2004 SUSE Linux AG Nuremberg\n"); printf("Licensed under GNU General Public License\n\n"); printf("--alsa <port> ALSA Sequencer Port (e.g. 64:0)\n"); printf("--program <ch> <prg> Program Change\n"); printf("--control <ch> <ctrl> <val> Control Change\n"); printf("--bend <ch> <val> Pitch Bend (0..16383, center = 8192)\n"); printf("--note <ch> <on> <num> <vel> Note On (on=1) Note Off (on=0)\n"); printf("--off <ch> All Notes Off\n\n"); exit(EXIT_SUCCESS); } } if (valid < 2) { fprintf(stderr, "\nUsage: midisend PORT COMMAND PARAMETERS\n\n"); fprintf(stderr, "Type \'midisend -h\' for a list of valid commands.\n\n"); } else if (valid == 2) { snd_seq_event_output_direct(seq_handle, &ev); } }
int main(int argc, char **argv) { int c; snd_seq_t *seq; int queue = 0, convert_time = 0, convert_real = 0, exclusive = 0; int command = SUBSCRIBE; int list_perm = 0; int client; int list_subs = 0; snd_seq_port_subscribe_t *subs; snd_seq_addr_t sender, dest; #ifdef ENABLE_NLS setlocale(LC_ALL, ""); textdomain(PACKAGE); #endif while ((c = getopt_long(argc, argv, "dior:t:elx", long_option, NULL)) != -1) { switch (c) { case 'd': command = UNSUBSCRIBE; break; case 'i': command = LIST; list_perm |= LIST_INPUT; break; case 'o': command = LIST; list_perm |= LIST_OUTPUT; break; case 'e': exclusive = 1; break; case 'r': queue = atoi(optarg); convert_time = 1; convert_real = 1; break; case 't': queue = atoi(optarg); convert_time = 1; convert_real = 0; break; case 'l': list_subs = 1; break; case 'x': command = REMOVE_ALL; break; default: usage(); exit(1); } } if (snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { fprintf(stderr, _("can't open sequencer\n")); return 1; } snd_lib_error_set_handler(error_handler); switch (command) { case LIST: do_search_port(seq, list_perm, list_subs ? print_port_and_subs : print_port); snd_seq_close(seq); return 0; case REMOVE_ALL: remove_all_connections(seq); snd_seq_close(seq); return 0; } /* connection or disconnection */ if (optind + 2 > argc) { snd_seq_close(seq); usage(); exit(1); } if ((client = snd_seq_client_id(seq)) < 0) { snd_seq_close(seq); fprintf(stderr, _("can't get client id\n")); return 1; } /* set client info */ if (snd_seq_set_client_name(seq, "ALSA Connector") < 0) { snd_seq_close(seq); fprintf(stderr, _("can't set client info\n")); return 1; } /* set subscription */ if (snd_seq_parse_address(seq, &sender, argv[optind]) < 0) { snd_seq_close(seq); fprintf(stderr, _("invalid sender address %s\n"), argv[optind]); return 1; } if (snd_seq_parse_address(seq, &dest, argv[optind + 1]) < 0) { snd_seq_close(seq); fprintf(stderr, _("invalid destination address %s\n"), argv[optind + 1]); return 1; } snd_seq_port_subscribe_alloca(&subs); snd_seq_port_subscribe_set_sender(subs, &sender); snd_seq_port_subscribe_set_dest(subs, &dest); snd_seq_port_subscribe_set_queue(subs, queue); snd_seq_port_subscribe_set_exclusive(subs, exclusive); snd_seq_port_subscribe_set_time_update(subs, convert_time); snd_seq_port_subscribe_set_time_real(subs, convert_real); if (command == UNSUBSCRIBE) { if (snd_seq_get_port_subscription(seq, subs) < 0) { snd_seq_close(seq); fprintf(stderr, _("No subscription is found\n")); return 1; } if (snd_seq_unsubscribe_port(seq, subs) < 0) { snd_seq_close(seq); fprintf(stderr, _("Disconnection failed (%s)\n"), snd_strerror(errno)); return 1; } } else { if (snd_seq_get_port_subscription(seq, subs) == 0) { snd_seq_close(seq); fprintf(stderr, _("Connection is already subscribed\n")); return 1; } if (snd_seq_subscribe_port(seq, subs) < 0) { snd_seq_close(seq); fprintf(stderr, _("Connection failed (%s)\n"), snd_strerror(errno)); return 1; } } snd_seq_close(seq); return 0; }
/** 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 ); } }
int main (int argc, char *argv[]) { snd_seq_t *seq_handle; int npfd; struct pollfd *pfd; seq_handle = open_seq(); npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN); pfd = malloc(npfd * sizeof(*pfd)); snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN); if (argc >= 2) { snd_seq_addr_t addr; if (snd_seq_parse_address(seq_handle, &addr, argv[1]) == 0) { if (snd_seq_connect_from(seq_handle, portid, addr.client, addr.port) == 0) { printf("Connected to %s\n", argv[1]); } } } int i; for (i=2; i<argc; i++) channels |= 1<<(atoi(argv[i])-1); OLRenderParams params; memset(¶ms, 0, sizeof params); params.rate = 48000; params.on_speed = 2.0/50.0; params.off_speed = 2.0/35.0; params.start_wait = 6; params.start_dwell = 1; params.curve_dwell = 0; params.corner_dwell = 0; params.curve_angle = cosf(30.0*(M_PI/180.0)); // 30 deg params.end_dwell = 0; params.end_wait = 7; params.flatness = 0.00001; params.snap = 1/100000.0; params.render_flags = RENDER_GRAYSCALE; if(olInit(3, 30000) < 0) return 1; olSetRenderParams(¶ms); float time = 0; float ftime; int frames = 0; float nps = 0; avgnotes = 5; while(1) { olLoadIdentity(); int drawn = draw(); if (drawn < 2) draw(); ftime = olRenderFrame(100); float t = powf(0.3, ftime); avgnotes = avgnotes * t + (nps+2) * (1.0f-t); animate(ftime); int notes = 0; if (poll(pfd, npfd, 0) > 0) notes = midi_action(seq_handle); int pnotes = (notes+2)/3; nps = pnotes / ftime * 1.2; frames++; time += ftime; printf("Frame time: %f, Avg FPS:%f, Cur FPS:%f, %d, nps:%3d, avgnotes:%f\n", ftime, frames/time, 1/ftime, notes, (int)nps, avgnotes); } olShutdown(); exit (0); }