File: audioio-proxy.cpp

package info (click to toggle)
ecasound 2.9.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,292 kB
  • sloc: cpp: 39,475; sh: 4,335; lisp: 1,918; ansic: 1,883; makefile: 888; python: 617; ruby: 202
file content (180 lines) | stat: -rw-r--r-- 4,647 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// ------------------------------------------------------------------------
// audioio-proxy.cpp: Generic interface for objects that act as
//                    proxies for other objects of type AUDIO_IO.
// Copyright (C) 2002,2005,2008,2011 Kai Vehmanen
//
// Attributes:
//     eca-style-version: 3
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
// ------------------------------------------------------------------------

#include <kvu_dbc.h>

#include "samplebuffer.h"
#include "audioio-null.h"
#include "audioio-proxy.h"

AUDIO_IO_PROXY::AUDIO_IO_PROXY(void) 
  : buffersize_rep(0),
    child_initialized_rep(false)
{
  child_repp = new NULLFILE("uninitialized proxy child");
}

AUDIO_IO_PROXY::~AUDIO_IO_PROXY(void)
{ 
  delete child_repp; // either null or the actual child object
}

/**
 * Sets a new proxy target object. The old 
 * target (if any) is deleted.
 */
void AUDIO_IO_PROXY::set_child(AUDIO_IO* v)
{ 
  if (child_repp != 0) 
    delete child_repp;
  
  child_repp = v;

  child_initialized_rep = true;
}

/**
 * Releases the current child without deleting Itx.
 */
void AUDIO_IO_PROXY::release_child_no_delete(void)
{
  child_repp = new NULLFILE("uninitialized proxy child");
  child_initialized_rep = false;
}

/**
 * Prepares child object for opening.
 * 
 * Sets the audio objects parameters, which have an effect
 * at open time, to those of the parent object.
 */
void AUDIO_IO_PROXY::pre_child_open(void)
{
  child()->set_buffersize(buffersize());
  child()->set_io_mode(io_mode());
  child()->set_audio_format(audio_format());
  child()->set_samples_per_second(samples_per_second());
}

/**
 * Checks if any audio parameters were changed
 * during child's open(), fetches any changes and
 * sets the object length.
 */
void AUDIO_IO_PROXY::post_child_open(void)
{
  if (child()->locked_audio_format() == true) {
    set_audio_format(child()->audio_format());
  }
  set_length_in_samples(child()->length_in_samples());
}

void AUDIO_IO_PROXY::set_buffersize(long int samples)
{
  buffersize_rep = samples;
  child_repp->set_buffersize(samples);
}

void AUDIO_IO_PROXY::set_channels(SAMPLE_SPECS::channel_t v)
{
  AUDIO_IO::set_channels(v);
  child_repp->set_channels(v);
}

void AUDIO_IO_PROXY::set_sample_format(Sample_format v) throw(ECA_ERROR&)
{
  AUDIO_IO::set_sample_format(v);
  child_repp->set_sample_format(v);
}

void AUDIO_IO_PROXY::set_audio_format(const ECA_AUDIO_FORMAT& f_str)
{
  AUDIO_IO::set_audio_format(f_str);
  child_repp->set_audio_format(f_str);
}

void AUDIO_IO_PROXY::toggle_interleaved_channels(bool v)
{
  AUDIO_IO::toggle_interleaved_channels(v);
  child_repp->toggle_interleaved_channels(v);
}

void AUDIO_IO_PROXY::set_samples_per_second(SAMPLE_SPECS::sample_rate_t v)
{
  AUDIO_IO::set_samples_per_second(v);
  child_repp->set_samples_per_second(v);
}

std::string AUDIO_IO_PROXY::parameter_names(void) const
{
  return child_repp->parameter_names();
}

void AUDIO_IO_PROXY::set_parameter(int param, std::string value)
{
  AUDIO_IO::set_parameter(param, value);
  child_repp->set_parameter(param, value);
}

std::string AUDIO_IO_PROXY::get_parameter(int param) const
{
  return child_repp->get_parameter(param);
}

void AUDIO_IO_PROXY::start_io(void)
{
  AUDIO_IO_BARRIER *barrier
    = dynamic_cast<AUDIO_IO_BARRIER*>(child_repp);

  if (barrier)
    barrier->start_io();

}

void AUDIO_IO_PROXY::stop_io(void)
{
  AUDIO_IO_BARRIER *barrier
    = dynamic_cast<AUDIO_IO_BARRIER*>(child_repp);

  if (barrier)
    barrier->stop_io();
}

std::string AUDIO_IO_PROXY::child_params_as_string(int first, std::vector<std::string>* params)
{
  int last = params->size();
  string res;
  for (int n = first; n <= last; n++) {
    std::string v = get_parameter(n);

    /* note: as we are passing a filename plus optional params, we
     *       need to escape any commans in the filename */
    if (v.find(",") != string::npos)
      v = "\"" + v + "\"";

    res += v;
    if (n != last)
      res += ",";
  }
  return res;
}