Mercurial > hg > svcore
comparison data/midi/rtmidi/RtMidi.cpp @ 843:e802e550a1f2
Drop std:: from cout, cerr, endl -- pull these in through Debug.h
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 13:35:08 +0000 |
parents | 1424aa29ae95 |
children | 59e7fe1b1003 |
comparison
equal
deleted
inserted
replaced
842:23d3a6eca5c3 | 843:e802e550a1f2 |
---|---|
38 // RtMidi: Version 1.0.8 | 38 // RtMidi: Version 1.0.8 |
39 | 39 |
40 #include "RtMidi.h" | 40 #include "RtMidi.h" |
41 #include <sstream> | 41 #include <sstream> |
42 | 42 |
43 using std::cerr; | |
44 using std::endl; | |
45 | |
43 //*********************************************************************// | 46 //*********************************************************************// |
44 // Common RtMidi Definitions | 47 // Common RtMidi Definitions |
45 //*********************************************************************// | 48 //*********************************************************************// |
46 | 49 |
47 RtMidi :: RtMidi() | 50 RtMidi :: RtMidi() |
50 } | 53 } |
51 | 54 |
52 void RtMidi :: error( RtError::Type type ) | 55 void RtMidi :: error( RtError::Type type ) |
53 { | 56 { |
54 if (type == RtError::WARNING) { | 57 if (type == RtError::WARNING) { |
55 std::cerr << '\n' << errorString_ << "\n\n"; | 58 cerr << '\n' << errorString_ << "\n\n"; |
56 } | 59 } |
57 else if (type == RtError::DEBUG_WARNING) { | 60 else if (type == RtError::DEBUG_WARNING) { |
58 #if defined(__RTMIDI_DEBUG__) | 61 #if defined(__RTMIDI_DEBUG__) |
59 std::cerr << '\n' << errorString_ << "\n\n"; | 62 cerr << '\n' << errorString_ << "\n\n"; |
60 #endif | 63 #endif |
61 } | 64 } |
62 else { | 65 else { |
63 std::cerr << '\n' << errorString_ << "\n\n"; | 66 cerr << '\n' << errorString_ << "\n\n"; |
64 throw RtError( errorString_, type ); | 67 throw RtError( errorString_, type ); |
65 } | 68 } |
66 } | 69 } |
67 | 70 |
68 //*********************************************************************// | 71 //*********************************************************************// |
240 else { | 243 else { |
241 // As long as we haven't reached our queue size limit, push the message. | 244 // As long as we haven't reached our queue size limit, push the message. |
242 if ( data->queueLimit > data->queue.size() ) | 245 if ( data->queueLimit > data->queue.size() ) |
243 data->queue.push( message ); | 246 data->queue.push( message ); |
244 else | 247 else |
245 std::cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; | 248 cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; |
246 } | 249 } |
247 message.bytes.clear(); | 250 message.bytes.clear(); |
248 } | 251 } |
249 } | 252 } |
250 else { | 253 else { |
302 else { | 305 else { |
303 // As long as we haven't reached our queue size limit, push the message. | 306 // As long as we haven't reached our queue size limit, push the message. |
304 if ( data->queueLimit > data->queue.size() ) | 307 if ( data->queueLimit > data->queue.size() ) |
305 data->queue.push( message ); | 308 data->queue.push( message ); |
306 else | 309 else |
307 std::cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; | 310 cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; |
308 } | 311 } |
309 message.bytes.clear(); | 312 message.bytes.clear(); |
310 } | 313 } |
311 iByte += size; | 314 iByte += size; |
312 } | 315 } |
713 int result; | 716 int result; |
714 apiData->bufferSize = 32; | 717 apiData->bufferSize = 32; |
715 result = snd_midi_event_new( 0, &apiData->coder ); | 718 result = snd_midi_event_new( 0, &apiData->coder ); |
716 if ( result < 0 ) { | 719 if ( result < 0 ) { |
717 data->doInput = false; | 720 data->doInput = false; |
718 std::cerr << "\nRtMidiIn::alsaMidiHandler: error initializing MIDI event parser!\n\n"; | 721 cerr << "\nRtMidiIn::alsaMidiHandler: error initializing MIDI event parser!\n\n"; |
719 return 0; | 722 return 0; |
720 } | 723 } |
721 unsigned char *buffer = (unsigned char *) malloc( apiData->bufferSize ); | 724 unsigned char *buffer = (unsigned char *) malloc( apiData->bufferSize ); |
722 if ( buffer == NULL ) { | 725 if ( buffer == NULL ) { |
723 data->doInput = false; | 726 data->doInput = false; |
724 std::cerr << "\nRtMidiIn::alsaMidiHandler: error initializing buffer memory!\n\n"; | 727 cerr << "\nRtMidiIn::alsaMidiHandler: error initializing buffer memory!\n\n"; |
725 return 0; | 728 return 0; |
726 } | 729 } |
727 snd_midi_event_init( apiData->coder ); | 730 snd_midi_event_init( apiData->coder ); |
728 snd_midi_event_no_status( apiData->coder, 1 ); // suppress running status messages | 731 snd_midi_event_no_status( apiData->coder, 1 ); // suppress running status messages |
729 | 732 |
736 } | 739 } |
737 | 740 |
738 // If here, there should be data. | 741 // If here, there should be data. |
739 result = snd_seq_event_input( apiData->seq, &ev ); | 742 result = snd_seq_event_input( apiData->seq, &ev ); |
740 if ( result == -ENOSPC ) { | 743 if ( result == -ENOSPC ) { |
741 std::cerr << "\nRtMidiIn::alsaMidiHandler: MIDI input buffer overrun!\n\n"; | 744 cerr << "\nRtMidiIn::alsaMidiHandler: MIDI input buffer overrun!\n\n"; |
742 continue; | 745 continue; |
743 } | 746 } |
744 else if ( result <= 0 ) { | 747 else if ( result <= 0 ) { |
745 std::cerr << "RtMidiIn::alsaMidiHandler: unknown MIDI input error!\n"; | 748 cerr << "RtMidiIn::alsaMidiHandler: unknown MIDI input error!\n"; |
746 continue; | 749 continue; |
747 } | 750 } |
748 | 751 |
749 // This is a bit weird, but we now have to decode an ALSA MIDI | 752 // This is a bit weird, but we now have to decode an ALSA MIDI |
750 // event (back) into MIDI bytes. We'll ignore non-MIDI types. | 753 // event (back) into MIDI bytes. We'll ignore non-MIDI types. |
753 | 756 |
754 switch ( ev->type ) { | 757 switch ( ev->type ) { |
755 | 758 |
756 case SND_SEQ_EVENT_PORT_SUBSCRIBED: | 759 case SND_SEQ_EVENT_PORT_SUBSCRIBED: |
757 #if defined(__RTMIDI_DEBUG__) | 760 #if defined(__RTMIDI_DEBUG__) |
758 std::cout << "RtMidiIn::alsaMidiHandler: port connection made!\n"; | 761 cout << "RtMidiIn::alsaMidiHandler: port connection made!\n"; |
759 #endif | 762 #endif |
760 break; | 763 break; |
761 | 764 |
762 case SND_SEQ_EVENT_PORT_UNSUBSCRIBED: | 765 case SND_SEQ_EVENT_PORT_UNSUBSCRIBED: |
763 #if defined(__RTMIDI_DEBUG__) | 766 #if defined(__RTMIDI_DEBUG__) |
764 SVDEBUG << "RtMidiIn::alsaMidiHandler: port connection has closed!\n"; | 767 SVDEBUG << "RtMidiIn::alsaMidiHandler: port connection has closed!\n"; |
765 // FIXME: this is called for all unsubscribe events, even ones | 768 // FIXME: this is called for all unsubscribe events, even ones |
766 //not related to this particular connection. As it stands, I | 769 //not related to this particular connection. As it stands, I |
767 //see no data provided in the "source" and "dest" fields so | 770 //see no data provided in the "source" and "dest" fields so |
768 //there is nothing we can do about this at this time. | 771 //there is nothing we can do about this at this time. |
769 // std::cout << "sender = " << ev->source.client << ", dest = " << ev->dest.port << endl; | 772 // cout << "sender = " << ev->source.client << ", dest = " << ev->dest.port << endl; |
770 #endif | 773 #endif |
771 //data->doInput = false; | 774 //data->doInput = false; |
772 break; | 775 break; |
773 | 776 |
774 case SND_SEQ_EVENT_QFRAME: // MIDI time code | 777 case SND_SEQ_EVENT_QFRAME: // MIDI time code |
786 apiData->bufferSize = ev->data.ext.len; | 789 apiData->bufferSize = ev->data.ext.len; |
787 free( buffer ); | 790 free( buffer ); |
788 buffer = (unsigned char *) malloc( apiData->bufferSize ); | 791 buffer = (unsigned char *) malloc( apiData->bufferSize ); |
789 if ( buffer == NULL ) { | 792 if ( buffer == NULL ) { |
790 data->doInput = false; | 793 data->doInput = false; |
791 std::cerr << "\nRtMidiIn::alsaMidiHandler: error resizing buffer memory!\n\n"; | 794 cerr << "\nRtMidiIn::alsaMidiHandler: error resizing buffer memory!\n\n"; |
792 break; | 795 break; |
793 } | 796 } |
794 } | 797 } |
795 | 798 |
796 default: | 799 default: |
797 nBytes = snd_midi_event_decode( apiData->coder, buffer, apiData->bufferSize, ev ); | 800 nBytes = snd_midi_event_decode( apiData->coder, buffer, apiData->bufferSize, ev ); |
798 if ( nBytes <= 0 ) { | 801 if ( nBytes <= 0 ) { |
799 #if defined(__RTMIDI_DEBUG__) | 802 #if defined(__RTMIDI_DEBUG__) |
800 std::cerr << "\nRtMidiIn::alsaMidiHandler: event parsing error or not a MIDI event!\n\n"; | 803 cerr << "\nRtMidiIn::alsaMidiHandler: event parsing error or not a MIDI event!\n\n"; |
801 #endif | 804 #endif |
802 break; | 805 break; |
803 } | 806 } |
804 | 807 |
805 // The ALSA sequencer has a maximum buffer size for MIDI sysex | 808 // The ALSA sequencer has a maximum buffer size for MIDI sysex |
845 else { | 848 else { |
846 // As long as we haven't reached our queue size limit, push the message. | 849 // As long as we haven't reached our queue size limit, push the message. |
847 if ( data->queueLimit > data->queue.size() ) | 850 if ( data->queueLimit > data->queue.size() ) |
848 data->queue.push( message ); | 851 data->queue.push( message ); |
849 else | 852 else |
850 std::cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; | 853 cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; |
851 } | 854 } |
852 } | 855 } |
853 | 856 |
854 if ( buffer ) free( buffer ); | 857 if ( buffer ) free( buffer ); |
855 snd_midi_event_free( apiData->coder ); | 858 snd_midi_event_free( apiData->coder ); |
1377 unsigned short size; | 1380 unsigned short size; |
1378 MDevent event; | 1381 MDevent event; |
1379 int fd = mdGetFd( apiData->port ); | 1382 int fd = mdGetFd( apiData->port ); |
1380 if ( fd < 0 ) { | 1383 if ( fd < 0 ) { |
1381 data->doInput = false; | 1384 data->doInput = false; |
1382 std::cerr << "\nRtMidiIn::irixMidiHandler: error getting port descriptor!\n\n"; | 1385 cerr << "\nRtMidiIn::irixMidiHandler: error getting port descriptor!\n\n"; |
1383 return 0; | 1386 return 0; |
1384 } | 1387 } |
1385 | 1388 |
1386 fd_set mask, rmask; | 1389 fd_set mask, rmask; |
1387 FD_ZERO( &mask ); | 1390 FD_ZERO( &mask ); |
1402 } | 1405 } |
1403 | 1406 |
1404 // If here, there should be data. | 1407 // If here, there should be data. |
1405 result = mdReceive( apiData->port, &event, 1); | 1408 result = mdReceive( apiData->port, &event, 1); |
1406 if ( result <= 0 ) { | 1409 if ( result <= 0 ) { |
1407 std::cerr << "\nRtMidiIn::irixMidiHandler: MIDI input read error!\n\n"; | 1410 cerr << "\nRtMidiIn::irixMidiHandler: MIDI input read error!\n\n"; |
1408 continue; | 1411 continue; |
1409 } | 1412 } |
1410 | 1413 |
1411 message.timeStamp = event.stamp * 0.000000001; | 1414 message.timeStamp = event.stamp * 0.000000001; |
1412 | 1415 |
1431 else { | 1434 else { |
1432 // As long as we haven't reached our queue size limit, push the message. | 1435 // As long as we haven't reached our queue size limit, push the message. |
1433 if ( data->queueLimit > data->queue.size() ) | 1436 if ( data->queueLimit > data->queue.size() ) |
1434 data->queue.push( message ); | 1437 data->queue.push( message ); |
1435 else | 1438 else |
1436 std::cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; | 1439 cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; |
1437 } | 1440 } |
1438 message.bytes.clear(); | 1441 message.bytes.clear(); |
1439 } | 1442 } |
1440 } | 1443 } |
1441 } | 1444 } |
1475 else { | 1478 else { |
1476 // As long as we haven't reached our queue size limit, push the message. | 1479 // As long as we haven't reached our queue size limit, push the message. |
1477 if ( data->queueLimit > data->queue.size() ) | 1480 if ( data->queueLimit > data->queue.size() ) |
1478 data->queue.push( message ); | 1481 data->queue.push( message ); |
1479 else | 1482 else |
1480 std::cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; | 1483 cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; |
1481 } | 1484 } |
1482 message.bytes.clear(); | 1485 message.bytes.clear(); |
1483 } | 1486 } |
1484 } | 1487 } |
1485 | 1488 |
1835 // one or two minutes. | 1838 // one or two minutes. |
1836 if ( apiData->sysexBuffer->dwBytesRecorded > 0 ) { | 1839 if ( apiData->sysexBuffer->dwBytesRecorded > 0 ) { |
1837 //if ( sysex->dwBytesRecorded > 0 ) { | 1840 //if ( sysex->dwBytesRecorded > 0 ) { |
1838 MMRESULT result = midiInAddBuffer( apiData->inHandle, apiData->sysexBuffer, sizeof(MIDIHDR) ); | 1841 MMRESULT result = midiInAddBuffer( apiData->inHandle, apiData->sysexBuffer, sizeof(MIDIHDR) ); |
1839 if ( result != MMSYSERR_NOERROR ) | 1842 if ( result != MMSYSERR_NOERROR ) |
1840 std::cerr << "\nRtMidiIn::midiInputCallback: error sending sysex to Midi device!!\n\n"; | 1843 cerr << "\nRtMidiIn::midiInputCallback: error sending sysex to Midi device!!\n\n"; |
1841 | 1844 |
1842 if ( data->ignoreFlags & 0x01 ) return; | 1845 if ( data->ignoreFlags & 0x01 ) return; |
1843 } | 1846 } |
1844 else return; | 1847 else return; |
1845 } | 1848 } |
1851 else { | 1854 else { |
1852 // As long as we haven't reached our queue size limit, push the message. | 1855 // As long as we haven't reached our queue size limit, push the message. |
1853 if ( data->queueLimit > data->queue.size() ) | 1856 if ( data->queueLimit > data->queue.size() ) |
1854 data->queue.push( apiData->message ); | 1857 data->queue.push( apiData->message ); |
1855 else | 1858 else |
1856 std::cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; | 1859 cerr << "\nRtMidiIn: message queue limit reached!!\n\n"; |
1857 } | 1860 } |
1858 | 1861 |
1859 // Clear the vector for the next input message. | 1862 // Clear the vector for the next input message. |
1860 apiData->message.bytes.clear(); | 1863 apiData->message.bytes.clear(); |
1861 } | 1864 } |