Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.1KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Client.H"
  19. namespace JACK
  20. {
  21. Client::Client ( )
  22. {
  23. _freewheeling = false;
  24. _zombified = false;
  25. _client = NULL;
  26. _xruns = 0;
  27. }
  28. Client::~Client ( )
  29. {
  30. jack_deactivate( _client );
  31. jack_client_close( _client );
  32. }
  33. /*******************/
  34. /* Static Wrappers */
  35. /*******************/
  36. int
  37. Client::process ( nframes_t nframes, void *arg )
  38. {
  39. return ((Client*)arg)->process( nframes );
  40. }
  41. int
  42. Client::sync ( jack_transport_state_t state, jack_position_t *pos, void *arg )
  43. {
  44. return ((Client*)arg)->sync( state, pos );
  45. }
  46. int
  47. Client::xrun ( void *arg )
  48. {
  49. ++((Client*)arg)->_xruns;
  50. return ((Client*)arg)->xrun();
  51. }
  52. void
  53. Client::timebase ( jack_transport_state_t state, jack_nframes_t nframes, jack_position_t *pos, int new_pos, void *arg )
  54. {
  55. ((Client*)arg)->timebase( state, nframes, pos, new_pos );
  56. }
  57. void
  58. Client::freewheel ( int starting, void *arg )
  59. {
  60. ((Client*)arg)->_freewheeling = starting;
  61. ((Client*)arg)->freewheel( starting );
  62. }
  63. int
  64. Client::buffer_size ( nframes_t nframes, void *arg )
  65. {
  66. return ((Client*)arg)->buffer_size( nframes );
  67. }
  68. void
  69. Client::thread_init ( void *arg )
  70. {
  71. ((Client*)arg)->thread_init();
  72. }
  73. void
  74. Client::shutdown ( void *arg )
  75. {
  76. ((Client*)arg)->_zombified = true;
  77. ((Client*)arg)->shutdown();
  78. }
  79. /** Connect to JACK using client name /client_name/. Return a static
  80. * pointer to actual name as reported by JACK */
  81. const char *
  82. Client::init ( const char *client_name )
  83. {
  84. if (( _client = jack_client_open ( client_name, (jack_options_t)0, NULL )) == 0 )
  85. return NULL;
  86. #define set_callback( name ) jack_set_ ## name ## _callback( _client, &Client:: name , this )
  87. set_callback( thread_init );
  88. set_callback( process );
  89. set_callback( xrun );
  90. set_callback( freewheel );
  91. set_callback( buffer_size );
  92. /* FIXME: should we wait to register this until after the project
  93. has been loaded (and we have disk threads running)? */
  94. set_callback( sync );
  95. jack_set_timebase_callback( _client, 0, &Client::timebase, this );
  96. jack_on_shutdown( _client, &Client::shutdown, this );
  97. jack_activate( _client );
  98. _sample_rate = frame_rate();
  99. return jack_get_client_name( _client );
  100. }
  101. /* THREAD: RT */
  102. /** enter or leave freehweeling mode */
  103. void
  104. Client::freewheeling ( bool yes )
  105. {
  106. if ( jack_set_freewheel( _client, yes ) )
  107. ;
  108. // WARNING( "Unkown error while setting freewheeling mode" );
  109. }
  110. }