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.

378 lines
11KB

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