cwIo.h/cpp : Replaced use of flow proc audioFileIn with audioDevFile() enable/seek API.

This commit is contained in:
kevin 2023-02-19 14:18:53 -05:00
parent 20175d29f9
commit a523b03ea9

View File

@ -250,6 +250,8 @@ namespace cw
const object_t* presets_cfg; const object_t* presets_cfg;
object_t* flow_proc_dict; object_t* flow_proc_dict;
const object_t* flow_cfg; const object_t* flow_cfg;
const char* in_audio_dev_file;
unsigned in_audio_dev_idx;
midi_record_play::handle_t mrpH; midi_record_play::handle_t mrpH;
@ -290,7 +292,6 @@ namespace cw
bool useLiveMidiFl; // use incoming MIDI to drive program (otherwise use score file) bool useLiveMidiFl; // use incoming MIDI to drive program (otherwise use score file)
bool trackMidiFl; // apply presets based on MIDI location (otherwise respond only to direct manipulation of fragment control) bool trackMidiFl; // apply presets based on MIDI location (otherwise respond only to direct manipulation of fragment control)
bool audioFileSrcFl;
unsigned pvWndSmpCnt; unsigned pvWndSmpCnt;
bool sdBypassFl; bool sdBypassFl;
@ -376,6 +377,12 @@ namespace cw
goto errLabel; goto errLabel;
} }
if((rc = params_cfgRef->getv_opt( "in_audio_dev_file", app->in_audio_dev_file)) != kOkRC )
{
rc = cwLogError(rc,"Parse of optional cfg. params failed..");
goto errLabel;
}
_apply_command_line_args(app,argc,argv); _apply_command_line_args(app,argc,argv);
if((app->scoreFn = filesys::expandPath( app->scoreFn )) == nullptr ) if((app->scoreFn = filesys::expandPath( app->scoreFn )) == nullptr )
@ -658,15 +665,16 @@ namespace cw
{ {
rc_t rc = kOkRC; rc_t rc = kOkRC;
if( app->audioFileSrcFl ) if( app->in_audio_dev_idx != kInvalidIdx )
{ {
if((rc = io_flow::set_variable_value( app->ioFlowH, flow_cross::kAllDestId, "aud_in", "on_off", flow::kAnyChIdx, false )) != kOkRC ) if((rc = audioDeviceEnable( app->ioH, app->in_audio_dev_idx, true, false )) != kOkRC )
{ {
rc = cwLogError(kInvalidArgRC,"Attempt to set audio in 'on/off' value to 'off' failed."); rc = cwLogError(rc,"Enable failed on audio device input file.");
goto errLabel; goto errLabel;
} }
} }
if((rc = midi_record_play::stop(app->mrpH)) != kOkRC ) if((rc = midi_record_play::stop(app->mrpH)) != kOkRC )
{ {
rc = cwLogError(rc,"MIDI stop failed."); rc = cwLogError(rc,"MIDI stop failed.");
@ -695,18 +703,17 @@ namespace cw
//midi_record_play::half_pedal_params( app->mrpH, app->hpDelayMs, app->hpPitch, app->hpVel, app->hpPedalVel, app->hpDurMs, app->hpDnDelayMs ); //midi_record_play::half_pedal_params( app->mrpH, app->hpDelayMs, app->hpPitch, app->hpVel, app->hpPedalVel, app->hpDurMs, app->hpDnDelayMs );
// If we are using an audio file as the audio source if( app->in_audio_dev_idx != kInvalidIdx )
if( app->audioFileSrcFl )
{ {
if((rc = io_flow::set_variable_value( app->ioFlowH, flow_cross::kAllDestId, "aud_in", "on_off", flow::kAnyChIdx, true )) != kOkRC ) if((rc = audioDeviceSeek( app->ioH, app->in_audio_dev_idx, true, 0 )) != kOkRC )
{ {
rc = cwLogError(kInvalidArgRC,"Attempt to set audio in 'on/off' value to 'on' failed."); rc = cwLogError(rc,"Seek failed on audio device input file.");
goto errLabel; goto errLabel;
} }
if((rc = io_flow::set_variable_value( app->ioFlowH, flow_cross::kAllDestId, "aud_in", "seekSecs", flow::kAnyChIdx, 0.0f )) != kOkRC ) if((rc = audioDeviceEnable( app->ioH, app->in_audio_dev_idx, true, true )) != kOkRC )
{ {
rc = cwLogError(kInvalidArgRC,"Attempt to rewind audio file failed."); rc = cwLogError(rc,"Enable failed on audio device input file.");
goto errLabel; goto errLabel;
} }
} }
@ -2377,7 +2384,6 @@ cw::rc_t cw::preset_sel_app::main( const object_t* cfg, int argc, const char* ar
rc_t rc; rc_t rc;
app_t app = { .hpDelayMs=250, .hpPedalVel=127, .hpPitch=64, .hpVel=64, .hpDurMs=500, .hpDnDelayMs=1000, app_t app = { .hpDelayMs=250, .hpPedalVel=127, .hpPitch=64, .hpVel=64, .hpDurMs=500, .hpDnDelayMs=1000,
.trackMidiFl = true, .trackMidiFl = true,
.audioFileSrcFl = false,
.pvWndSmpCnt = 512, .pvWndSmpCnt = 512,
.sdBypassFl = false, .sdBypassFl = false,
.sdInGain = 1.0, .sdInGain = 1.0,
@ -2407,6 +2413,23 @@ cw::rc_t cw::preset_sel_app::main( const object_t* cfg, int argc, const char* ar
io::report(app.ioH); io::report(app.ioH);
// if an input audio file is being used
app.in_audio_dev_idx = kInvalidIdx;
if( app.in_audio_dev_file != nullptr )
{
if((app.in_audio_dev_idx = audioDeviceLabelToIndex(app.ioH, app.in_audio_dev_file )) == kInvalidIdx )
{
rc = cwLogError(kInvalidArgRC,"The input audio device file '%s' could not be found.",cwStringNullGuard(app.in_audio_dev_file));
goto errLabel;
}
if((rc = audioDeviceEnable( app.ioH, app.in_audio_dev_idx, true, false )) != kOkRC )
{
rc = cwLogError(rc,"The input audio device file disable failed.");
goto errLabel;
}
}
// create the preset selection state object // create the preset selection state object
if((rc = create(app.psH, app.presets_cfg )) != kOkRC ) if((rc = create(app.psH, app.presets_cfg )) != kOkRC )
{ {