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.

131 lines
3.5KB

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