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.

150 lines
4.2KB

  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_client_close( _client );
  31. }
  32. /** Tell JACK to calling process callback. This MUST be called in
  33. * an inheriting class' destructor */
  34. void
  35. Client::deactivate ( )
  36. {
  37. jack_deactivate( _client );
  38. }
  39. /*******************/
  40. /* Static Wrappers */
  41. /*******************/
  42. int
  43. Client::process ( nframes_t nframes, void *arg )
  44. {
  45. return ((Client*)arg)->process( nframes );
  46. }
  47. int
  48. Client::sync ( jack_transport_state_t state, jack_position_t *pos, void *arg )
  49. {
  50. return ((Client*)arg)->sync( state, pos );
  51. }
  52. int
  53. Client::xrun ( void *arg )
  54. {
  55. ++((Client*)arg)->_xruns;
  56. return ((Client*)arg)->xrun();
  57. }
  58. void
  59. Client::timebase ( jack_transport_state_t state, jack_nframes_t nframes, jack_position_t *pos, int new_pos, void *arg )
  60. {
  61. ((Client*)arg)->timebase( state, nframes, pos, new_pos );
  62. }
  63. void
  64. Client::freewheel ( int starting, void *arg )
  65. {
  66. ((Client*)arg)->_freewheeling = starting;
  67. ((Client*)arg)->freewheel( starting );
  68. }
  69. int
  70. Client::buffer_size ( nframes_t nframes, void *arg )
  71. {
  72. return ((Client*)arg)->buffer_size( nframes );
  73. }
  74. void
  75. Client::thread_init ( void *arg )
  76. {
  77. ((Client*)arg)->thread_init();
  78. }
  79. void
  80. Client::shutdown ( void *arg )
  81. {
  82. ((Client*)arg)->_zombified = true;
  83. ((Client*)arg)->shutdown();
  84. }
  85. /** Connect to JACK using client name /client_name/. Return a static
  86. * pointer to actual name as reported by JACK */
  87. const char *
  88. Client::init ( const char *client_name )
  89. {
  90. if (( _client = jack_client_open ( client_name, (jack_options_t)0, NULL )) == 0 )
  91. return NULL;
  92. #define set_callback( name ) jack_set_ ## name ## _callback( _client, &Client:: name , this )
  93. set_callback( thread_init );
  94. set_callback( process );
  95. set_callback( xrun );
  96. set_callback( freewheel );
  97. set_callback( buffer_size );
  98. /* FIXME: should we wait to register this until after the project
  99. has been loaded (and we have disk threads running)? */
  100. set_callback( sync );
  101. jack_set_timebase_callback( _client, 0, &Client::timebase, this );
  102. jack_on_shutdown( _client, &Client::shutdown, this );
  103. jack_activate( _client );
  104. _sample_rate = frame_rate();
  105. return jack_get_client_name( _client );
  106. }
  107. /* THREAD: RT */
  108. /** enter or leave freehweeling mode */
  109. void
  110. Client::freewheeling ( bool yes )
  111. {
  112. if ( jack_set_freewheel( _client, yes ) )
  113. ;
  114. // WARNING( "Unkown error while setting freewheeling mode" );
  115. }
  116. }