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.

362 lines
10KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2009 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. #pragma once
  19. #include <FL/Fl.H>
  20. #include <FL/Fl_Group.H>
  21. #include <stdlib.h>
  22. #include "util/debug.h"
  23. #include <vector>
  24. #include "util/Thread.H"
  25. #include "Loggable.H"
  26. #include "JACK/Port.H"
  27. class Chain;
  28. class Module_Parameter_Editor;
  29. class Fl_Menu_;
  30. class Fl_Menu_Button;
  31. class Fl_Button;
  32. class Module : public Fl_Group, public Loggable {
  33. int _ins;
  34. int _outs;
  35. int _instances;
  36. nframes_t _nframes;
  37. Chain *_chain;
  38. bool _is_default;
  39. bool _bypass;
  40. Module_Parameter_Editor *_editor;
  41. void init ( void );
  42. void insert_menu_cb ( const Fl_Menu_ *m );
  43. static void insert_menu_cb ( Fl_Widget *w, void *v );
  44. void menu_cb ( const Fl_Menu_ *m );
  45. static void menu_cb ( Fl_Widget *w, void *v );
  46. Fl_Menu_Button & menu ( void ) const;
  47. public:
  48. /* true if this module was added by default and not under normal user control */
  49. bool is_default ( void ) const { return _is_default; }
  50. void is_default ( bool v ) { _is_default = v; }
  51. class Port
  52. {
  53. /* char *type_names[] = { "Audio", "Control" }; */
  54. /* char *direction_names[] = { "Input", "Output" }; */
  55. void update_connected_port_buffer ( void )
  56. {
  57. if ( connected() )
  58. connected_port()->_buf = _buf;
  59. }
  60. public:
  61. enum Direction { INPUT, OUTPUT };
  62. enum Type { AUDIO, CONTROL };
  63. /* hints for control ports (specifically control inputs) */
  64. struct Hints
  65. {
  66. enum Type { LINEAR, LOGARITHMIC, BOOLEAN, INTEGER };
  67. Type type;
  68. bool ranged;
  69. float minimum;
  70. float maximum;
  71. float default_value;
  72. int dimensions;
  73. Hints ( )
  74. {
  75. type = LINEAR;
  76. ranged = false;
  77. minimum = 0;
  78. maximum = 0;
  79. default_value = 0.0f;
  80. dimensions = 1;
  81. }
  82. };
  83. Hints hints;
  84. Port ( Module *module, Direction direction, Type type, const char *name = 0 )
  85. {
  86. _name = name;
  87. _direction = direction;
  88. _type = type;
  89. _buf = 0;
  90. _nframes = 0;
  91. _connected = 0;
  92. _module = module;
  93. }
  94. Port ( const Port& p )
  95. {
  96. _name = p._name;
  97. _direction = p._direction;
  98. _type = p._type;
  99. _buf = p._buf;
  100. _nframes = p._nframes;
  101. _connected = p._connected;
  102. _module = p._module;
  103. hints = p.hints;
  104. }
  105. virtual ~Port ( )
  106. {
  107. // disconnect();
  108. }
  109. const char *name ( void ) const { return _name; }
  110. Type type ( void ) const { return _type; }
  111. Direction direction ( void ) const { return _direction; }
  112. Module * module ( void ) const { return _module; }
  113. nframes_t nframes ( void ) const { return _nframes; }
  114. void buffer ( void *buf, nframes_t nframes ) { _buf = buf; _nframes = nframes; };
  115. void *buffer ( void ) const { return _buf; }
  116. void control_value_no_callback ( float f )
  117. {
  118. THREAD_ASSERT( UI );
  119. if ( buffer() )
  120. {
  121. *((float*)buffer()) = f;
  122. }
  123. }
  124. void control_value ( float f )
  125. {
  126. control_value_no_callback( f );
  127. _module->handle_control_changed( this );
  128. }
  129. float control_value ( ) const
  130. {
  131. if ( buffer() )
  132. return *((float*)buffer());
  133. else
  134. return 0.0f;
  135. }
  136. bool connected ( void ) const { return _connected; }
  137. Port *connected_port ( void ) const
  138. {
  139. return _connected;
  140. }
  141. void connect_to ( Port *to )
  142. {
  143. _buf = to->_buf;
  144. to->_connected = this;
  145. _connected = to;
  146. }
  147. void connect_to ( void *buf )
  148. {
  149. _buf = buf;
  150. update_connected_port_buffer();
  151. }
  152. void disconnect ( void )
  153. {
  154. if ( _connected && _connected != (void*)0x01 )
  155. {
  156. _connected->_connected = NULL;
  157. _connected = NULL;
  158. }
  159. else
  160. _connected = NULL;
  161. /* FIXME: do something! */
  162. }
  163. private:
  164. Port *_connected;
  165. Type _type;
  166. Direction _direction;
  167. const char *_name;
  168. void *_buf;
  169. nframes_t _nframes;
  170. Module *_module;
  171. };
  172. void bbox ( int &X, int &Y, int &W, int &H )
  173. {
  174. X = x() + 5;
  175. Y = y() + 5;
  176. W = w() - 10;
  177. H = h() - 10;
  178. }
  179. Module ( int W, int H, const char *L = 0 );
  180. Module ( );
  181. Module ( bool is_default, int W, int H, const char *L = 0 );
  182. virtual ~Module ( );
  183. LOG_NAME_FUNC( Module );
  184. nframes_t nframes ( void ) const { return _nframes; }
  185. void resize_buffers ( nframes_t v ) { _nframes = v; }
  186. int instances ( void ) const { return _instances; }
  187. void instances ( int i ) { _instances = i; }
  188. bool is_being_controlled ( void ) const
  189. {
  190. for ( nframes_t i = control_input.size(); i--; )
  191. if ( control_input[i].connected() )
  192. return true;
  193. return false;
  194. }
  195. bool is_controlling ( void ) const
  196. {
  197. for ( nframes_t i = control_output.size(); i--; )
  198. if ( control_output[i].connected() )
  199. return true;
  200. return false;
  201. }
  202. virtual const char *name ( void ) const = 0;
  203. std::vector<Port> audio_input;
  204. std::vector<Port> audio_output;
  205. std::vector<Port> control_input;
  206. std::vector<Port> control_output;
  207. void add_port ( const Port &p )
  208. {
  209. if ( p.type() == Port::AUDIO && p.direction() == Port::INPUT )
  210. audio_input.push_back( p );
  211. else if ( p.type() == Port::AUDIO && p.direction() == Port::OUTPUT )
  212. audio_output.push_back( p );
  213. else if ( p.type() == Port::CONTROL && p.direction() == Port::INPUT )
  214. control_input.push_back( p );
  215. else if ( p.type() == Port::CONTROL && p.direction() == Port::OUTPUT )
  216. control_output.push_back( p );
  217. }
  218. int noutputs ( void ) const
  219. {
  220. return audio_output.size();
  221. }
  222. int ninputs ( void ) const
  223. {
  224. return audio_input.size();
  225. }
  226. int ncontrol_inputs ( void ) const
  227. {
  228. return control_input.size();
  229. }
  230. int ncontrol_outputs ( void ) const
  231. {
  232. return control_output.size();
  233. }
  234. bool bypass ( void ) const { return _bypass; }
  235. void bypass ( bool v ) { _bypass = v; redraw(); }
  236. int control_input_port_index ( Port *p )
  237. {
  238. for ( nframes_t i = control_input.size(); i--; )
  239. if ( &control_input[i] == p )
  240. return i;
  241. return -1;
  242. }
  243. int control_output_port_index ( Port *p )
  244. {
  245. for ( nframes_t i = control_output.size(); i--; )
  246. if ( &control_output[i] == p )
  247. return i;
  248. return -1;
  249. }
  250. Chain *chain ( void ) const { return _chain; }
  251. void chain ( Chain * v ) { _chain = v; }
  252. char *get_parameters ( void ) const;
  253. void set_parameters ( const char * );
  254. virtual bool initialize ( void ) { return true; }
  255. /* for the given number of inputs, return how many outputs this
  256. * plugin would have. -1 if this plugin can't support so many
  257. * inputs. */
  258. virtual int can_support_inputs ( int n ) = 0;
  259. /* called by the chain whenever we need to adjust our input
  260. * channel configuration, but only if can_support_inputs() returns
  261. * true */
  262. virtual bool configure_inputs ( int n ) = 0;
  263. virtual void process ( nframes_t ) = 0;
  264. /* called whenever the value of a control port is changed.
  265. This can be used to take appropriate action from the GUI thread */
  266. virtual void handle_control_changed ( Port * ) { }
  267. /* called whenever the name of the chain changes (usually because
  268. * the name of the mixer strip changed). */
  269. virtual void handle_chain_name_changed () {}
  270. virtual void handle_port_connection_change () {}
  271. protected:
  272. void draw_connections ( void );
  273. void draw_label ( void );
  274. void draw_box ( void );
  275. virtual void draw ( void ) { Module::draw_box(); Module::draw_label(); }
  276. virtual int handle ( int m );
  277. virtual void get ( Log_Entry &e ) const;
  278. virtual void set ( Log_Entry &e );
  279. public:
  280. void command_open_parameter_editor();
  281. void command_activate ( void );
  282. void command_deactivate ( void );
  283. void command_remove ( void );
  284. };