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
3.8KB

  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. /* Wrapper for a JACK audio port */
  19. #include "Port.H"
  20. #include <string.h>
  21. #include "Engine.H"
  22. #include <stdio.h> // sprintf
  23. static const char *name_for_port ( Port::type_e dir, const char *base, int n, const char *type );
  24. int
  25. Port::max_name ( void )
  26. {
  27. return jack_port_name_size() - jack_client_name_size() - 6;
  28. }
  29. /* nframes is the number of frames to buffer */
  30. Port::Port ( jack_port_t *port )
  31. {
  32. _port = port;
  33. _name = jack_port_name( _port );
  34. }
  35. Port::Port ( const char *name, type_e dir )
  36. {
  37. activate( name, dir );
  38. }
  39. Port::Port ( type_e dir, const char *base, int n, const char *type )
  40. {
  41. const char *name = name_for_port( dir, base, n, type );
  42. activate( name, dir );
  43. }
  44. Port::~Port ( )
  45. {
  46. /* if ( _port ) */
  47. /* jack_port_unregister( engine->client(), _port ); */
  48. }
  49. static const char *
  50. name_for_port ( Port::type_e dir, const char *base, int n, const char *type )
  51. {
  52. static char pname[ 512 ];
  53. const char *dir_s = dir == Port::Output ? "out" : "in";
  54. strncpy( pname, base, Port::max_name() );
  55. pname[ Port::max_name() - 1 ] = '\0';
  56. int l = strlen( pname );
  57. if ( type )
  58. snprintf( pname + l, sizeof( pname ) - l, "/%s-%s-%d", type, dir_s, n + 1 );
  59. else
  60. snprintf( pname + l, sizeof( pname ) - l, "/%s-%d", dir_s, n + 1 );
  61. return pname;
  62. }
  63. void
  64. Port::activate ( const char *name, type_e dir )
  65. {
  66. _name = name;
  67. _port = jack_port_register( engine->client(), _name,
  68. JACK_DEFAULT_AUDIO_TYPE,
  69. dir == Output ? JackPortIsOutput : JackPortIsInput,
  70. 0 );
  71. }
  72. void
  73. Port::shutdown ( void )
  74. {
  75. if ( _port )
  76. jack_port_unregister( engine->client(), _port );
  77. }
  78. /** rename port */
  79. bool
  80. Port::name ( const char *name )
  81. {
  82. _name = name;
  83. return 0 == jack_port_set_name( _port, name );
  84. }
  85. bool
  86. Port::name ( const char *base, int n, const char *type )
  87. {
  88. return name( name_for_port( this->type(), base, n, type ) );
  89. }
  90. void
  91. Port::write ( sample_t *buf, nframes_t nframes )
  92. {
  93. memcpy( buffer( nframes ), buf, nframes * sizeof( sample_t ) );
  94. }
  95. void
  96. Port::read ( sample_t *buf, nframes_t nframes )
  97. {
  98. memcpy( buf, buffer( nframes ), nframes * sizeof( sample_t ) );
  99. }
  100. void *
  101. Port::buffer ( nframes_t nframes )
  102. {
  103. return jack_port_get_buffer( _port, nframes );
  104. }
  105. void
  106. Port::silence ( nframes_t nframes )
  107. {
  108. memset( buffer( nframes ), 0, nframes * sizeof( sample_t ) );
  109. #include "const.h"
  110. }