1
// ------------------------------------------------------------------------
2
// audioio-audioseq.cpp: Audio clip sequencer class.
3
// Copyright (C) 2008,2010 Kai Vehmanen
6
// eca-style-version: 3 (see Ecasound Programmer's Guide)
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.
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.
18
// You should have received a copy of the GNU General Public License
19
// along with this program; if not, write to the Free Software
20
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
// ------------------------------------------------------------------------
30
#include <kvu_message_item.h>
31
#include <kvu_numtostr.h>
34
#include "eca-object-factory.h"
35
#include "samplebuffer.h"
36
#include "audioio-acseq.h"
38
#include "eca-error.h"
39
#include "eca-logger.h"
43
using SAMPLE_SPECS::sample_pos_t;
46
* FIXME notes (last update 2008-03-04)
51
AUDIO_CLIP_SEQUENCER::AUDIO_CLIP_SEQUENCER ()
53
set_label("audiocseq");
55
/* note: index of last sequencer parameter (one if no
56
* extra parameters); params beyond this value are
57
* passed on to the child object */
58
child_param_offset_rep = 1;
60
cseq_mode_rep = AUDIO_CLIP_SEQUENCER::cseq_none;
63
AUDIO_CLIP_SEQUENCER::~AUDIO_CLIP_SEQUENCER(void)
67
AUDIO_CLIP_SEQUENCER* AUDIO_CLIP_SEQUENCER::clone(void) const
69
AUDIO_CLIP_SEQUENCER* target = new AUDIO_CLIP_SEQUENCER();
70
for(int n = 0; n < number_of_params(); n++) {
71
target->set_parameter(n + 1, get_parameter(n + 1));
77
void AUDIO_CLIP_SEQUENCER::open(void) throw(AUDIO_IO::SETUP_ERROR &)
79
if (io_mode() != AUDIO_IO::io_read)
80
throw(SETUP_ERROR(SETUP_ERROR::unexpected, "AUDIOIO-ACLIPSEQ: Only read mode supported."));
82
ECA_LOG_MSG(ECA_LOGGER::user_objects,
83
"Opening audio clip sequencer in mode: "
86
/* note: change behaviour based on first param */
87
if (cseq_mode_rep == AUDIO_CLIP_SEQUENCER::cseq_loop) {
88
/* following is specific to looping */
89
AUDIO_SEQUENCER_BASE::toggle_looping(true);
90
DBC_CHECK(finite_length_stream() != true);
91
AUDIO_SEQUENCER_BASE::set_child_object_string(
92
child_params_as_string(1 + child_param_offset_rep, ¶ms_rep));
94
else if (cseq_mode_rep == AUDIO_CLIP_SEQUENCER::cseq_select) {
95
AUDIO_SEQUENCER_BASE::toggle_looping(false);
96
AUDIO_SEQUENCER_BASE::set_child_start_position(get_parameter(2));
97
AUDIO_SEQUENCER_BASE::set_child_length(get_parameter(3));
98
AUDIO_SEQUENCER_BASE::set_child_object_string(
99
child_params_as_string(1 + child_param_offset_rep, ¶ms_rep));
101
else if (cseq_mode_rep == AUDIO_CLIP_SEQUENCER::cseq_play_at) {
102
/* following is specific to play-at */
103
AUDIO_SEQUENCER_BASE::toggle_looping(false);
104
AUDIO_SEQUENCER_BASE::set_child_offset(get_parameter(2));
105
AUDIO_SEQUENCER_BASE::set_child_object_string(
106
child_params_as_string(1 + child_param_offset_rep, ¶ms_rep));
109
throw(SETUP_ERROR(SETUP_ERROR::unexpected, "AUDIOIO-ACLIPSEQ: Unknown audio sequencing mode (loop, select, ...)."));
111
AUDIO_SEQUENCER_BASE::open();
113
/* step: set additional child params (if any) */
114
int numparams = child()->number_of_params();
115
for(int n = 0; n < numparams; n++) {
116
child()->set_parameter(n + 1, get_parameter(n + 1 + child_param_offset_rep));
117
if (child()->variable_params())
118
numparams = child()->number_of_params();
122
void AUDIO_CLIP_SEQUENCER::close(void)
124
AUDIO_SEQUENCER_BASE::close();
127
std::string AUDIO_CLIP_SEQUENCER::parameter_names(void) const
129
std::string baseparams;
131
if (cseq_mode_rep == AUDIO_CLIP_SEQUENCER::cseq_loop)
132
baseparams += std::string("audioloop");
133
else if (cseq_mode_rep == AUDIO_CLIP_SEQUENCER::cseq_select)
134
baseparams += std::string("select,start-sec,dur-sec");
135
else if (cseq_mode_rep == AUDIO_CLIP_SEQUENCER::cseq_play_at)
136
baseparams += std::string("playat,pos-sec");
138
baseparams += std::string("acseqtype");
140
if (is_child_initialized() == true) {
141
baseparams += "," + child()->parameter_names();
144
/* create a generic parameter name list */
145
for (size_t i = 1; i < params_rep.size(); i++) {
146
baseparams += ",param" + kvu_numtostr(i);
150
ECA_LOG_MSG(ECA_LOGGER::system_objects,
151
"param list: " + baseparams);
156
void AUDIO_CLIP_SEQUENCER::set_parameter(int param, string value)
158
ECA_LOG_MSG(ECA_LOGGER::user_objects,
159
AUDIO_IO::parameter_set_to_string(param, value));
161
if (param > static_cast<int>(params_rep.size())) params_rep.resize(param);
164
params_rep[param - 1] = value;
168
if (value == "audioloop") {
169
cseq_mode_rep = AUDIO_CLIP_SEQUENCER::cseq_loop;
170
child_param_offset_rep = 1;
172
else if (value == "select") {
173
cseq_mode_rep = AUDIO_CLIP_SEQUENCER::cseq_select;
174
child_param_offset_rep = 3;
176
else if (value == "playat") {
177
cseq_mode_rep = AUDIO_CLIP_SEQUENCER::cseq_play_at;
178
child_param_offset_rep = 2;
181
cseq_mode_rep = AUDIO_CLIP_SEQUENCER::cseq_none;
182
child_param_offset_rep = 1;
186
if (param > child_param_offset_rep &&
187
is_child_initialized() == true) {
188
child()->set_parameter(param - child_param_offset_rep, value);
191
AUDIO_IO::set_parameter(param, value);
194
string AUDIO_CLIP_SEQUENCER::get_parameter(int param) const
196
ECA_LOG_MSG(ECA_LOGGER::system_objects,
197
AUDIO_IO::parameter_get_to_string(param));
199
if (param > 0 && param < static_cast<int>(params_rep.size()) + 1) {
200
if (param > child_param_offset_rep &&
201
is_child_initialized() == true) {
202
params_rep[param - 1] = child()->get_parameter(param - child_param_offset_rep);
204
return params_rep[param - 1];