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.

132 lines
3.6KB

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