~ubuntu-branches/ubuntu/lucid/ecasound2.2/lucid

« back to all changes in this revision

Viewing changes to libecasound/eca-control.h

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2009-11-02 18:22:35 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091102182235-4ngh7699dmkgonyu
Tags: 2.7.0-1
* New upstream release.
* Depend on libreadline-dev instead of libreadline5-dev by request of
  Mattias Klose. It's now libreadline6-dev. (closes: #553748)
* Update menu file to use section Applications/ instead of Apps/.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ------------------------------------------------------------------------
 
2
// eca-control.h: ECA_CONTROL class
 
3
// Copyright (C) 2009 Kai Vehmanen
 
4
//
 
5
// Attributes:
 
6
//     eca-style-version: 3
 
7
//
 
8
// This program is free software; you can redistribute it and/or modify
 
9
// it under the terms of the GNU General Public License as published by
 
10
// the Free Software Foundation; either version 2 of the License, or
 
11
// (at your option) any later version.
 
12
// 
 
13
// This program is distributed in the hope that it will be useful,
 
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
// GNU General Public License for more details.
 
17
// 
 
18
// You should have received a copy of the GNU General Public License
 
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
// ------------------------------------------------------------------------
 
21
 
1
22
#ifndef INCLUDED_ECA_CONTROL_H
2
23
#define INCLUDED_ECA_CONTROL_H
3
24
 
 
25
#include <list>
4
26
#include <string>
5
27
#include <vector>
6
28
 
 
29
#include "kvu_locks.h"
 
30
 
 
31
#include "ctrl-source.h"
 
32
#include "eca-audio-format.h"
 
33
#include "eca-chainop.h"
 
34
#include "eca-chainsetup-edit.h"
 
35
#include "eca-control-dump.h"
 
36
#include "eca-control-main.h"
7
37
#include "eca-iamode-parser.h"
8
 
#include "eca-control-objects.h"
9
 
#include "eca-control-dump.h"
10
38
#include "sample-specs.h"
11
39
 
 
40
class AUDIO_IO;
12
41
class CHAIN_OPERATOR;
 
42
class GENERIC_CONTROLLER;
13
43
class ECA_CHAINSETUP;
 
44
class ECA_ENGINE;
14
45
class ECA_OBJECT_MAP;
 
46
class ECA_SESSION;
15
47
 
16
48
/**
17
 
 * Class for controlling the whole ecasound library
 
49
 * High-level interface to libecasound functionality
 
50
 *
 
51
 * @see ECA_CONTROL_MAIN, ECA_CONTROL_MT
18
52
 *
19
53
 * Related design patters: Facade (GoF185)
20
54
 *
21
55
 * @author Kai Vehmanen
22
56
 */
23
 
class ECA_CONTROL : public ECA_CONTROL_OBJECTS,
24
 
                    public ECA_IAMODE_PARSER {
 
57
class ECA_CONTROL : public ECA_IAMODE_PARSER,
 
58
                    public ECA_CONTROL_MAIN {
25
59
 
26
60
 
27
61
 public:
34
68
 
35
69
  /*@}*/
36
70
 
37
 
  /** @name Public functions for issuing command */
38
 
  /*@{*/
39
 
 
40
 
  /**
41
 
   * Parses and executes a string containing a single Ecasound 
42
 
   * Interactive Mode (EIAM) command and its arguments.
43
 
   *
44
 
   * Result of the command can be queried with last_value_to_string().
45
 
   */
46
 
  void command(const std::string& cmd_and_args);
47
 
 
48
 
  /**
49
 
   * A special version of 'command()' which parses a command taking 
50
 
   * a single double parameter.
51
 
   *
52
 
   * Result of the command can be queried with last_value_to_string().
53
 
   */
54
 
  void command_float_arg(const std::string& cmd, double arg);
 
71
  // -------------------------------------------------------------------
 
72
 
 
73
  /** @name ECA_CONTROL_MAIN subset */
 
74
 
 
75
  virtual bool is_running(void) const;
 
76
  virtual bool is_connected(void) const;
 
77
  virtual bool is_selected(void) const;
 
78
  virtual bool is_finished(void) const;
 
79
  virtual bool is_valid(void) const;
 
80
  virtual bool is_engine_created(void) const;
 
81
  virtual bool is_engine_running(void) const;
 
82
 
 
83
  virtual void engine_start(void);
 
84
  virtual int start(void);
 
85
  virtual void stop(void);
 
86
  virtual void stop_on_condition(void);
 
87
  virtual int run(bool batchmode = true);
 
88
  virtual void quit(void);
 
89
  virtual void quit_async(void);
 
90
 
 
91
  virtual void connect_chainsetup(struct eci_return_value *retval);
 
92
  virtual void disconnect_chainsetup(void);
 
93
  virtual const ECA_CHAINSETUP* get_connected_chainsetup(void) const;
 
94
 
 
95
  virtual bool execute_edit_on_connected(const ECA::chainsetup_edit_t& edit);
 
96
  virtual bool execute_edit_on_selected(const ECA::chainsetup_edit_t& edit, int index = -1);
 
97
 
 
98
  virtual void print_last_value(struct eci_return_value *retval) const;
 
99
  virtual void command(const std::string& cmd_and_args, struct eci_return_value *retval);
 
100
  virtual void command_float_arg(const std::string& cmd, double arg, struct eci_return_value *retval);
 
101
 
 
102
  /*@}*/
 
103
 
 
104
  // -------------------------------------------------------------------
 
105
 
 
106
  /** @name Public functions for observing status 
 
107
   * (note: implemented in eca-control-base.cpp)
 
108
   */
 
109
  /*@{*/
 
110
 
 
111
  std::string engine_status(void) const;
 
112
 
 
113
  SAMPLE_SPECS::sample_pos_t length_in_samples(void) const;
 
114
  double length_in_seconds_exact(void) const;
 
115
  SAMPLE_SPECS::sample_pos_t position_in_samples(void) const;
 
116
  double position_in_seconds_exact(void) const;
 
117
 
 
118
  /*@}*/
 
119
 
 
120
  // -------------------------------------------------------------------
 
121
 
 
122
  /** @name Public functions for resource file access */
 
123
  /*@{*/
 
124
 
 
125
  /**
 
126
   * Get resource values from ~/.ecasoundrc
 
127
   */
 
128
  std::string resource_value(const std::string& key) const;
 
129
 
 
130
  /*@}*/
 
131
 
 
132
  // -------------------------------------------------------------------
 
133
 
 
134
  /** @name Public functions for chainsetup setup 
 
135
   * (note: implementated in eca-control-objects.cpp)
 
136
   */
 
137
  /*@{*/
 
138
 
 
139
  void add_chainsetup(const std::string& name);
 
140
  void remove_chainsetup(void);
 
141
  void load_chainsetup(const std::string& filename);
 
142
  void save_chainsetup(const std::string& filename);
 
143
  void select_chainsetup(const std::string& name);
 
144
  void select_chainsetup_by_index(int index);
 
145
  void edit_chainsetup(void);
 
146
 
 
147
  std::string selected_chainsetup(void) const;
 
148
  std::string connected_chainsetup(void) const;
 
149
 
 
150
  void change_chainsetup_position(double seconds);
 
151
  void change_chainsetup_position_samples(SAMPLE_SPECS::sample_pos_t samples);
 
152
  void set_chainsetup_position(double seconds);
 
153
  void set_chainsetup_position_samples(SAMPLE_SPECS::sample_pos_t samples);
 
154
 
 
155
  double chainsetup_position(double seconds) const;
 
156
  const ECA_CHAINSETUP* get_chainsetup(void) const;
 
157
  const ECA_CHAINSETUP* get_chainsetup_filename(const std::string& filename) const;
 
158
  std::vector<std::string> chainsetup_names(void) const;
 
159
  const std::string& chainsetup_filename(void) const;
 
160
  int chainsetup_buffersize(void) const;
 
161
 
 
162
  void set_chainsetup_filename(const std::string& name);
 
163
  void set_chainsetup_parameter(const std::string& name);
 
164
  void set_chainsetup_sample_format(const std::string& name);
 
165
  void set_chainsetup_processing_length_in_seconds(double value);
 
166
  void set_chainsetup_processing_length_in_samples(SAMPLE_SPECS::sample_pos_t value);
 
167
  void set_chainsetup_output_mode(int output_mode);
 
168
  void toggle_chainsetup_looping(void);
 
169
  void set_chainsetup_buffersize(int bsize);
 
170
 
 
171
  /*@}*/
 
172
 
 
173
  // -------------------------------------------------------------------
 
174
 
 
175
  /** @name Public functions for chain setup 
 
176
   * (note: implemented in eca-control-objects.cpp)
 
177
   */
 
178
  /*@{*/
 
179
 
 
180
  void add_chain(const std::string& names);
 
181
  void add_chains(const std::string& names);
 
182
  void add_chains(const std::vector<std::string>& names);
 
183
  void remove_chains(void);
 
184
  void select_chains_by_index(const std::vector<int>& index_numbers);
 
185
  void select_chain(const std::string& chain);
 
186
  void select_chains(const std::vector<std::string>& chains);
 
187
  void deselect_chains(const std::vector<std::string>& chains);
 
188
  void select_all_chains(void);
 
189
 
 
190
  const std::vector<std::string>& selected_chains(void) const;
 
191
  std::vector<std::string> chain_names(void) const;
 
192
  const CHAIN* get_chain(void) const;
 
193
 
 
194
  void clear_chains(void);
 
195
  void rename_chain(const std::string& name);
 
196
  void toggle_chain_muting(void);
 
197
  void toggle_chain_bypass(void);
 
198
 
 
199
  /*@}*/
 
200
 
 
201
  // -------------------------------------------------------------------
 
202
 
 
203
  /** @name Managing chain operators and controllers 
 
204
   * (note: implemented in eca-control-objects.cpp)
 
205
   */
 
206
  /*@{*/
 
207
 
 
208
  void add_audio_input(const std::string& filename);
 
209
  void remove_audio_input(void);
 
210
  void attach_audio_input(void);
 
211
  void select_audio_input(const std::string& name);
 
212
  void select_audio_input_by_index(int index);
 
213
 
 
214
  void add_audio_output(const std::string& filename);
 
215
  void add_default_output(void);
 
216
  void remove_audio_output(void);
 
217
  void attach_audio_output(void);
 
218
  void select_audio_output(const std::string& name);
 
219
  void select_audio_output_by_index(int index);
 
220
  void set_default_audio_format(const std::string& sfrm, int channels, long int srate, bool interleaving);
 
221
  void set_default_audio_format(const ECA_AUDIO_FORMAT& format);
 
222
  void set_default_audio_format_to_selected_input(void);
 
223
  void set_default_audio_format_to_selected_output(void);
 
224
 
 
225
  std::string attached_chains_input(AUDIO_IO* aiod) const;
 
226
  std::string attached_chains_output(AUDIO_IO* aiod) const;
 
227
  std::vector<std::string> attached_chains(const std::string& name) const;
 
228
 
 
229
  const AUDIO_IO* get_audio_input(void);
 
230
  std::vector<std::string> audio_input_names(void) const;
 
231
 
 
232
  const AUDIO_IO* get_audio_output(void);
 
233
  std::vector<std::string> audio_output_names(void) const;
 
234
 
 
235
  const ECA_AUDIO_FORMAT& default_audio_format(void) const;
 
236
  ECA_AUDIO_FORMAT get_audio_format(AUDIO_IO* aobj) const;
 
237
 
 
238
  /*@}*/
 
239
 
 
240
  // -------------------------------------------------------------------
 
241
 
 
242
  /** @name Managing chain operators and controllers
 
243
   * (note: implemented in eca-control-objects.cpp)
 
244
   */
 
245
  /*@{*/
 
246
 
 
247
  void add_chain_operator(const std::string& chainop_params);
 
248
  void add_chain_operator(CHAIN_OPERATOR* cotmp);
 
249
  void remove_chain_operator(void);
 
250
  void select_chain_operator(int chainop_id);
 
251
  void select_chain_operator_parameter(int param);
 
252
  void set_chain_operator_parameter(CHAIN_OPERATOR::parameter_t value);
 
253
  void set_chain_operator_parameter(int chain, int op, int param, CHAIN_OPERATOR::parameter_t value);
 
254
 
 
255
  int selected_chain_operator(void) const;
 
256
  int selected_chain_operator_parameter(void) const;
 
257
 
 
258
  const CHAIN_OPERATOR* get_chain_operator(void) const;
 
259
  CHAIN_OPERATOR::parameter_t get_chain_operator_parameter(void) const;
 
260
  std::vector<std::string> chain_operator_names(void) const;
 
261
  std::vector<std::string> chain_operator_parameter_names(void) const;
 
262
 
 
263
  void add_controller(const std::string& gcontrol_params);
 
264
  void select_controller(int ctrl_id);
 
265
  void select_controller_parameter(int param);
 
266
  void set_controller_parameter(CHAIN_OPERATOR::parameter_t value);
 
267
  void remove_controller(void);
 
268
 
 
269
  int selected_controller(void) const;
 
270
  int selected_controller_parameter(void) const;
 
271
  int selected_controller_target(void) const;
 
272
 
 
273
  const GENERIC_CONTROLLER* get_controller(void) const;
 
274
  CONTROLLER_SOURCE::parameter_t get_controller_parameter(void) const;
 
275
  std::vector<std::string> controller_names(void) const;
 
276
  std::vector<std::string> controller_parameter_names(void) const;
 
277
 
 
278
  /*@}*/
 
279
 
 
280
  // -------------------------------------------------------------------
 
281
 
 
282
  /** @name Public functions for executing ECI commands */
 
283
  /*@{*/
55
284
 
56
285
  /**
57
286
   * See ECA_IAMODE_PARSER for detailed decsription of 'action_id'.
60
289
   */
61
290
  void action(int action_id, const std::vector<std::string>& args);
62
291
 
 
292
  std::string last_error(void) const;
 
293
 
63
294
  /*@}*/
64
295
 
65
 
  /** @name Public functions for getting session information */
 
296
  // -------------------------------------------------------------------
 
297
 
 
298
  /** @name Implemenetations of ECI status commands */
66
299
  /*@{*/
67
300
 
68
301
  /**
114
347
 
115
348
  /*@}*/
116
349
 
117
 
  /** @name Public functions printing status information */
 
350
  // -------------------------------------------------------------------
 
351
 
 
352
  /** @name Helper functions */
118
353
  /*@{*/
119
354
 
120
 
  void print_last_value(void);
121
 
  std::string last_value_to_string(void);
 
355
  int float_to_string_precision(void) const { return(float_to_string_precision_rep); }
122
356
 
123
357
  /*@}*/
124
358
 
 
359
  // -------------------------------------------------------------------
 
360
 
 
361
 protected:
 
362
 
 
363
  void set_float_to_string_precision(int precision);
 
364
  std::string float_to_string(double n) const;
 
365
 
125
366
 private:
126
367
 
127
 
  std::vector<std::string> action_args_rep;
128
 
  double action_arg_f_rep; 
129
 
  bool action_arg_f_set_rep;
130
 
  bool action_ok;
131
 
  bool action_reconnect;
132
 
  bool action_restart;
133
 
  bool wellformed_mode_rep;
134
 
  ECA_CONTROL_DUMP ctrl_dump_rep;
 
368
  void set_last_string_list(const std::vector<std::string>& s);
 
369
  void set_last_string(const std::list<std::string>& s);
 
370
  void set_last_string(const std::string& s);
 
371
  void set_last_float(double v);
 
372
  void set_last_integer(int v);
 
373
  void set_last_long_integer(long int v);
 
374
  void set_last_error(const std::string& s);
 
375
  void clear_last_values(void);
 
376
 
 
377
  static void* start_normal_thread(void *ptr);
 
378
 
 
379
  void start_engine_sub(bool batchmode);
 
380
  void close_engine(void);
 
381
  void run_engine(void);
 
382
 
 
383
  std::string chainsetup_details_to_string(const ECA_CHAINSETUP* cs) const;
 
384
 
 
385
  void audio_input_as_selected(void);
 
386
  void audio_output_as_selected(void);
 
387
  void rewind_audio_object(double seconds);
 
388
  void forward_audio_object(double seconds);
 
389
  void set_audio_object_position(double seconds);
 
390
  void set_audio_object_position_samples(SAMPLE_SPECS::sample_pos_t samples);
 
391
  void wave_edit_audio_object(void);
 
392
 
 
393
  bool cond_stop_for_editing(void);
 
394
  void cond_start_after_editing(bool was_running);
 
395
 
 
396
  void send_chain_commands_to_engine(int command, double value);
135
397
 
136
398
  void action(int action_id);
137
399
  void check_action_preconditions(int action_id);
146
408
  long int first_action_argument_as_long_int(void) const;
147
409
  SAMPLE_SPECS::sample_pos_t first_action_argument_as_samples(void) const;
148
410
  const std::vector<std::string>& action_arguments_as_vector(void) const;
149
 
 
150
 
  std::string chainsetup_details_to_string(const ECA_CHAINSETUP* cs) const;
 
411
  void fill_command_retval(struct eci_return_value *retval) const;
 
412
  bool action_helper_check_cop_op_args(int copid, int coppid);
 
413
 
 
414
  ECA_ENGINE* engine_repp;
 
415
  ECA_SESSION* session_repp;
 
416
  ECA_CHAINSETUP* selected_chainsetup_repp;
 
417
  ECA_CONTROL_DUMP ctrl_dump_rep;
 
418
 
 
419
  bool req_batchmode_rep;
 
420
  pthread_t th_cqueue_rep;
 
421
  ATOMIC_INTEGER engine_exited_rep;
 
422
  int engine_pid_rep;
 
423
  int last_exec_res_rep;
 
424
  bool joining_rep;
 
425
 
 
426
  int float_to_string_precision_rep;
 
427
 
 
428
  AUDIO_IO* selected_audio_object_repp;
 
429
  AUDIO_IO* selected_audio_input_repp;
 
430
  AUDIO_IO* selected_audio_output_repp;
 
431
 
 
432
  struct eci_return_value last_retval_rep;
 
433
 
 
434
  bool wellformed_mode_rep;
 
435
 
 
436
  std::vector<std::string> action_args_rep;
 
437
  double action_arg_f_rep; 
 
438
  bool action_arg_f_set_rep;
 
439
  bool action_ok;
 
440
  bool action_reconnect;
 
441
  bool action_restart;
151
442
};
152
443
 
153
444
#endif