66 pthread_exit(
nullptr );
70 if ( ( err = snd_seq_open( &
seq_handle,
"hw", SND_SEQ_OPEN_DUPLEX, 0 ) ) < 0 ) {
71 __ERRORLOG( QString(
"Error opening ALSA sequencer: %1" ).arg( QString::fromLocal8Bit(snd_strerror(err)) ) );
72 pthread_exit(
nullptr );
75 snd_seq_set_client_name(
seq_handle,
"Hydrogen" );
79 SND_SEQ_PORT_CAP_WRITE |
80 SND_SEQ_PORT_CAP_SUBS_WRITE,
81 SND_SEQ_PORT_TYPE_APPLICATION
84 __ERRORLOG(
"Error creating sequencer port." );
85 pthread_exit(
nullptr );
90 SND_SEQ_PORT_CAP_READ |
91 SND_SEQ_PORT_CAP_SUBS_READ,
92 SND_SEQ_PORT_TYPE_APPLICATION
95 __ERRORLOG(
"Error creating sequencer port." );
96 pthread_exit(
nullptr );
101#ifdef H2CORE_HAVE_LASH
112 int m_local_addr_inport =
portId;
117 int m_dest_addr_port = -1;
118 int m_dest_addr_client = -1;
119 pDriver->
getPortInfo( sPortName, m_dest_addr_client, m_dest_addr_port );
120 __INFOLOG(
"MIDI input port name: " + sPortName );
121 __INFOLOG( QString(
"MIDI input addr client: %1").arg( m_dest_addr_client ) );
122 __INFOLOG( QString(
"MIDI input addr port: %1").arg( m_dest_addr_port ) );
124 if ( ( m_dest_addr_port != -1 ) && ( m_dest_addr_client != -1 ) ) {
125 snd_seq_port_subscribe_t *subs;
126 snd_seq_port_subscribe_alloca( &subs );
127 snd_seq_addr_t sender, dest;
129 sender.client = m_dest_addr_client;
130 sender.port = m_dest_addr_port;
131 dest.client = m_local_addr_client;
132 dest.port = m_local_addr_inport;
135 snd_seq_port_subscribe_set_sender( subs, &sender );
136 snd_seq_port_subscribe_set_dest( subs, &dest );
139 int ret = snd_seq_subscribe_port(
seq_handle, subs );
141 __ERRORLOG( QString(
"snd_seq_subscribe_port(%1:%2) error" ).arg( m_dest_addr_client ).arg( m_dest_addr_port ) );
149 m_dest_addr_port = -1;
150 m_dest_addr_client = -1;
151 pDriver->
getPortInfo( sPortName, m_dest_addr_client, m_dest_addr_port );
152 __INFOLOG(
"MIDI output port name: " + sPortName );
153 __INFOLOG( QString(
"MIDI output addr client: %1").arg( m_dest_addr_client ) );
154 __INFOLOG( QString(
"MIDI output addr port: %1").arg( m_dest_addr_port ) );
156 if ( ( m_dest_addr_port != -1 ) && ( m_dest_addr_client != -1 ) ) {
157 snd_seq_port_subscribe_t *subs;
158 snd_seq_port_subscribe_alloca( &subs );
159 snd_seq_addr_t sender, dest;
161 sender.client = m_local_addr_client;
162 sender.port = m_local_addr_outport;
163 dest.client = m_dest_addr_client;
164 dest.port = m_dest_addr_port;
167 snd_seq_port_subscribe_set_sender( subs, &sender );
168 snd_seq_port_subscribe_set_dest( subs, &dest );
171 int ret = snd_seq_subscribe_port(
seq_handle, subs );
173 __ERRORLOG( QString(
"snd_seq_subscribe_port(%1:%2) error" ).arg( m_dest_addr_client ).arg( m_dest_addr_port ) );
181 pfd = (
struct pollfd* )alloca(
npfd *
sizeof(
struct pollfd ) );
186 if ( poll(
pfd,
npfd, 100 ) > 0 ) {
194 pthread_exit(
nullptr );
262 switch ( ev->type ) {
263 case SND_SEQ_EVENT_NOTEON:
266 msg.
m_nData2 = ev->data.note.velocity;
270 case SND_SEQ_EVENT_NOTEOFF:
273 msg.
m_nData2 = ev->data.note.velocity;
277 case SND_SEQ_EVENT_CONTROLLER:
279 msg.
m_nData1 = ev->data.control.param;
280 msg.
m_nData2 = ev->data.control.value;
284 case SND_SEQ_EVENT_PGMCHANGE:
286 msg.
m_nData1 = ev->data.control.value;
290 case SND_SEQ_EVENT_KEYPRESS:
293 msg.
m_nData2 = ev->data.note.velocity;
297 case SND_SEQ_EVENT_CHANPRESS:
299 msg.
m_nData1 = ev->data.control.param;
300 msg.
m_nData2 = ev->data.control.value;
304 case SND_SEQ_EVENT_PITCHBEND:
306 msg.
m_nData1 = ev->data.control.param;
307 msg.
m_nData2 = ev->data.control.value;
311 case SND_SEQ_EVENT_SYSEX: {
313 snd_midi_event_t *seq_midi_parser;
314 if ( snd_midi_event_new( 32, &seq_midi_parser ) ) {
315 ERRORLOG(
"Error creating midi event parser" );
317 unsigned char midi_event_buffer[ 256 ];
318 int _bytes_read = snd_midi_event_decode( seq_midi_parser, midi_event_buffer, 32, ev );
320 for (
int i = 0; i < _bytes_read; ++i ) {
321 msg.
m_sysexData.push_back( midi_event_buffer[ i ] );
326 case SND_SEQ_EVENT_QFRAME:
328 msg.
m_nData1 = ev->data.control.value;
329 msg.
m_nData2 = ev->data.control.param;
332 case SND_SEQ_EVENT_SONGPOS:
334 msg.
m_nData1 = ev->data.control.value;
335 msg.
m_nData2 = ev->data.control.param;
338 case SND_SEQ_EVENT_SONGSEL:
340 msg.
m_nData1 = ev->data.control.value;
341 msg.
m_nData2 = ev->data.control.param;
344 case SND_SEQ_EVENT_TUNE_REQUEST:
346 msg.
m_nData1 = ev->data.control.value;
347 msg.
m_nData2 = ev->data.control.param;
350 case SND_SEQ_EVENT_CLOCK:
354 case SND_SEQ_EVENT_START:
358 case SND_SEQ_EVENT_CONTINUE:
362 case SND_SEQ_EVENT_STOP:
366 case SND_SEQ_EVENT_SENSING:
370 case SND_SEQ_EVENT_RESET:
374 case SND_SEQ_EVENT_CLIENT_EXIT:
375 INFOLOG(
"SND_SEQ_EVENT_CLIENT_EXIT" );
378 case SND_SEQ_EVENT_PORT_SUBSCRIBED:
379 INFOLOG(
"SND_SEQ_EVENT_PORT_SUBSCRIBED" );
382 case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
383 INFOLOG(
"SND_SEQ_EVENT_PORT_UNSUBSCRIBED" );
387 WARNINGLOG( QString(
"Unknown MIDI Event. type = %1" ).arg( (
int )ev->type ) );
393 snd_seq_free_event( ev );
394 }
while ( snd_seq_event_input_pending(
seq_handle, 0 ) > 0 );
399 std::vector<QString> inputList;
405 snd_seq_client_info_t *cinfo;
406 snd_seq_port_info_t *pinfo;
408 snd_seq_client_info_alloca( &cinfo );
409 snd_seq_client_info_set_client( cinfo, -1 );
412 while ( snd_seq_query_next_client(
seq_handle, cinfo ) >= 0 ) {
414 int client = snd_seq_client_info_get_client( cinfo );
417 snd_seq_port_info_alloca( &pinfo );
418 snd_seq_port_info_set_client( pinfo, client );
419 snd_seq_port_info_set_port( pinfo, -1 );
422 while ( snd_seq_query_next_port(
seq_handle, pinfo ) >= 0 ) {
425 int cap = snd_seq_port_info_get_capability( pinfo );
427 if ( snd_seq_client_id(
seq_handle ) != snd_seq_port_info_get_client( pinfo ) && snd_seq_port_info_get_client( pinfo ) != 0 ) {
430 ( cap & SND_SEQ_PORT_CAP_SUBS_WRITE ) != 0 &&
431 snd_seq_client_id(
seq_handle ) != snd_seq_port_info_get_client( pinfo )
433 INFOLOG( snd_seq_port_info_get_name( pinfo ) );
434 inputList.push_back( snd_seq_port_info_get_name( pinfo ) );
448 std::vector<QString> outputList;
454 snd_seq_client_info_t *cinfo;
455 snd_seq_port_info_t *pinfo;
457 snd_seq_client_info_alloca( &cinfo );
458 snd_seq_client_info_set_client( cinfo, -1 );
461 while ( snd_seq_query_next_client(
seq_handle, cinfo ) >= 0 ) {
463 int client = snd_seq_client_info_get_client( cinfo );
466 snd_seq_port_info_alloca( &pinfo );
467 snd_seq_port_info_set_client( pinfo, client );
468 snd_seq_port_info_set_port( pinfo, -1 );
471 while ( snd_seq_query_next_port(
seq_handle, pinfo ) >= 0 ) {
474 int cap = snd_seq_port_info_get_capability( pinfo );
476 if ( snd_seq_client_id(
seq_handle ) != snd_seq_port_info_get_client( pinfo ) && snd_seq_port_info_get_client( pinfo ) != 0 ) {
479 ( cap & SND_SEQ_PORT_CAP_SUBS_READ ) != 0 &&
480 snd_seq_client_id(
seq_handle ) != snd_seq_port_info_get_client( pinfo )
482 INFOLOG( snd_seq_port_info_get_name( pinfo ) );
483 outputList.push_back( snd_seq_port_info_get_name( pinfo ) );
507 snd_seq_client_info_t *cinfo;
508 snd_seq_port_info_t *pinfo;
510 snd_seq_client_info_alloca( &cinfo );
511 snd_seq_client_info_set_client( cinfo, -1 );
514 while ( snd_seq_query_next_client(
seq_handle, cinfo ) >= 0 ) {
516 int client = snd_seq_client_info_get_client( cinfo );
519 snd_seq_port_info_alloca( &pinfo );
520 snd_seq_port_info_set_client( pinfo, client );
521 snd_seq_port_info_set_port( pinfo, -1 );
524 while ( snd_seq_query_next_port(
seq_handle, pinfo ) >= 0 ) {
525 int cap = snd_seq_port_info_get_capability( pinfo );
526 if ( snd_seq_client_id(
seq_handle ) != snd_seq_port_info_get_client( pinfo ) && snd_seq_port_info_get_client( pinfo ) != 0 ) {
529 ( cap & SND_SEQ_PORT_CAP_SUBS_READ ) != 0 &&
530 snd_seq_client_id(
seq_handle ) != snd_seq_port_info_get_client( pinfo )
532 QString sName = snd_seq_port_info_get_name( pinfo );
533 if ( sName == sPortName ) {
534 nClient = snd_seq_port_info_get_client( pinfo );
535 nPort = snd_seq_port_info_get_port( pinfo );
537 INFOLOG( QString(
"nClient %1" ).arg( nClient ) );
538 INFOLOG( QString(
"nPort %1" ).arg( nPort ) );
545 ERRORLOG(
"Midi port " + sPortName +
" not found" );
565 snd_seq_ev_clear(&ev);
567 snd_seq_ev_set_subs(&ev);
568 snd_seq_ev_set_direct(&ev);
569 snd_seq_ev_set_noteoff(&ev, channel, key, velocity);
575 snd_seq_ev_clear(&ev);
577 snd_seq_ev_set_subs(&ev);
578 snd_seq_ev_set_direct(&ev);
581 snd_seq_ev_set_noteon(&ev, channel, key, velocity);
592 snd_seq_ev_clear(&ev);
594 ev.type = SND_SEQ_EVENT_CONTROLLER;
597 snd_seq_ev_set_subs(&ev);
598 snd_seq_ev_set_direct(&ev);
600 ev.data.control.param = param;
601 ev.data.control.value = value;
602 ev.data.control.channel = channel;
643 unsigned int numInstruments = instList->size();
644 for (
int index = 0; index < numInstruments; ++index) {
645 auto curInst = instList->get(index);
647 int channel = curInst->get_midi_out_channel();
651 int key = curInst->get_midi_out_note();
656 snd_seq_ev_clear(&ev);
658 snd_seq_ev_set_subs(&ev);
659 snd_seq_ev_set_direct(&ev);
660 snd_seq_ev_set_noteoff(&ev, channel, key, 0);