MidiSndio.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef SINGLE_SOURCE_COMPILE
  2. /* license */
  3. #include "MidiSndio.h"
  4. #ifdef LMMS_HAVE_SNDIO
  5. #include <QtGui/QLabel>
  6. #include <QtGui/QLineEdit>
  7. #ifdef LMMS_HAVE_STDLIB_H
  8. #include <stdlib.h>
  9. #endif
  10. #include <poll.h>
  11. #include "config_mgr.h"
  12. #include "gui_templates.h"
  13. MidiSndio::MidiSndio( void ) :
  14. MidiClientRaw(),
  15. m_quit( FALSE )
  16. {
  17. QString dev = probeDevice();
  18. if (dev == "")
  19. {
  20. m_hdl = mio_open( NULL, MIO_IN | MIO_OUT, 0 );
  21. }
  22. else
  23. {
  24. m_hdl = mio_open( dev.toAscii().data(), MIO_IN | MIO_OUT, 0 );
  25. }
  26. if( m_hdl == NULL )
  27. {
  28. printf( "sndio: failed opening sndio midi device\n" );
  29. return;
  30. }
  31. start( QThread::LowPriority );
  32. }
  33. MidiSndio::~MidiSndio()
  34. {
  35. if( isRunning() )
  36. {
  37. m_quit = TRUE;
  38. wait( 1000 );
  39. terminate();
  40. }
  41. }
  42. QString MidiSndio::probeDevice( void )
  43. {
  44. QString dev = configManager::inst()->value( "midisndio", "device" );
  45. return( dev );
  46. }
  47. void MidiSndio::sendByte( const Uint8 _c )
  48. {
  49. mio_write( m_hdl, &_c, 1 );
  50. }
  51. void MidiSndio::run( void )
  52. {
  53. struct pollfd pfd;
  54. nfds_t nfds;
  55. char buf[0x100], *p;
  56. size_t n;
  57. int ret;
  58. while( m_quit == FALSE && m_hdl )
  59. {
  60. nfds = mio_pollfd( m_hdl, &pfd, POLLIN );
  61. ret = poll( &pfd, nfds, 100 );
  62. if ( ret < 0 )
  63. break;
  64. if ( !ret || !( mio_revents( m_hdl, &pfd ) & POLLIN ) )
  65. continue;
  66. n = mio_read( m_hdl, buf, sizeof(buf) );
  67. if ( !n )
  68. {
  69. break;
  70. }
  71. for (p = buf; n > 0; n--, p++)
  72. {
  73. parseData( *p );
  74. }
  75. }
  76. }
  77. MidiSndio::setupWidget::setupWidget( QWidget * _parent ) :
  78. MidiClientRaw::setupWidget( MidiSndio::name(), _parent )
  79. {
  80. m_device = new QLineEdit( MidiSndio::probeDevice(), this );
  81. m_device->setGeometry( 10, 20, 160, 20 );
  82. QLabel * dev_lbl = new QLabel( tr( "DEVICE" ), this );
  83. dev_lbl->setFont( pointSize<6>( dev_lbl->font() ) );
  84. dev_lbl->setGeometry( 10, 40, 160, 10 );
  85. }
  86. MidiSndio::setupWidget::~setupWidget()
  87. {
  88. }
  89. void MidiSndio::setupWidget::saveSettings( void )
  90. {
  91. configManager::inst()->setValue( "midisndio", "device",
  92. m_device->text() );
  93. }
  94. #endif /* LMMS_HAVE_SNDIO */
  95. #endif /* SINGLE_SOURCE_COMPILE */