1 // ------------------------------------------------------------------------
2 // eca-control-interface.cpp: C++ implementation of the Ecasound
3 //                            Control Interface
4 // Copyright (C) 2000,2002,2009 Kai Vehmanen
5 //
6 // Attributes:
7 //     eca-style-version: 3 (see Ecasound Programmer's Guide)
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
22 // ------------------------------------------------------------------------
23 
24 #include <iostream>
25 #include <cassert>
26 
27 #include <ecasoundc.h>
28 
29 #include "eca-control-interface.h"
30 
31 using std::string;
32 using std::vector;
33 
34 /**
35  * Class constructor.
36  */
ECA_CONTROL_INTERFACE(void)37 ECA_CONTROL_INTERFACE::ECA_CONTROL_INTERFACE (void)
38 {
39   eci_repp = eci_init_r();
40 }
41 
42 /**
43  * Desctructor.
44  */
~ECA_CONTROL_INTERFACE(void)45 ECA_CONTROL_INTERFACE::~ECA_CONTROL_INTERFACE (void)
46 {
47   eci_cleanup_r(eci_repp);
48 }
49 
50 /**
51  * Checks whether ECI is ready for use.
52  */
ready(void)53 bool ECA_CONTROL_INTERFACE::ready(void)
54 {
55   return (eci_ready_r(eci_repp) != 0);
56 }
57 
58 /**
59  * Parse string mode command and act accordingly.
60  */
command(const string & cmd)61 void ECA_CONTROL_INTERFACE::command(const string& cmd)
62 {
63   eci_command_r(eci_repp, cmd.c_str());
64 }
65 
command_float_arg(const string & cmd,double arg)66 void ECA_CONTROL_INTERFACE::command_float_arg(const string& cmd, double arg)
67 {
68   eci_command_float_arg_r(eci_repp, cmd.c_str(), arg);
69 }
70 
last_string_list(void) const71 const vector<string>& ECA_CONTROL_INTERFACE::last_string_list(void) const
72 {
73   strlist_rep.clear();
74   int count = eci_last_string_list_count_r(eci_repp);
75   for(int n = 0; n < count; n++) {
76     const char* next = eci_last_string_list_item_r(eci_repp, n);
77     assert(next != NULL);
78     strlist_rep.push_back(string(next));
79   }
80 
81   return strlist_rep;
82 }
83 
last_string(void) const84 const string& ECA_CONTROL_INTERFACE::last_string(void) const
85 {
86   str_rep = string(eci_last_string_r(eci_repp));
87   return str_rep;
88 }
89 
last_float(void) const90 double ECA_CONTROL_INTERFACE::last_float(void) const
91 {
92   return eci_last_float_r(eci_repp);
93 }
94 
last_integer(void) const95 int ECA_CONTROL_INTERFACE::last_integer(void) const
96 {
97   return eci_last_integer_r(eci_repp);
98 }
99 
last_long_integer(void) const100 long int ECA_CONTROL_INTERFACE::last_long_integer(void) const
101 {
102   return eci_last_long_integer_r(eci_repp);
103 }
104 
last_error(void) const105 const string& ECA_CONTROL_INTERFACE::last_error(void) const
106 {
107   str_rep = string(eci_last_error_r(eci_repp));
108   return str_rep;
109 }
110 
last_type(void) const111 const string& ECA_CONTROL_INTERFACE::last_type(void) const
112 {
113   str_rep = string(eci_last_type_r(eci_repp));
114   return str_rep;
115 }
116 
error(void) const117 bool ECA_CONTROL_INTERFACE::error(void) const
118 {
119   return ((eci_error_r(eci_repp) != 0) ? true : false);
120 }
121 
events_available(void)122 bool ECA_CONTROL_INTERFACE::events_available(void)
123 {
124   return false;
125 }
126 
next_event(void)127 void ECA_CONTROL_INTERFACE::next_event(void)
128 {
129 }
130 
current_event(void)131 const string& ECA_CONTROL_INTERFACE::current_event(void)
132 {
133   str_rep = "";
134   return str_rep;
135 }
136