diff options
Diffstat (limited to 'libs/ardour/panner.cc')
-rw-r--r-- | libs/ardour/panner.cc | 288 |
1 files changed, 107 insertions, 181 deletions
diff --git a/libs/ardour/panner.cc b/libs/ardour/panner.cc index 0f6e78f84b..ee8e100e4a 100644 --- a/libs/ardour/panner.cc +++ b/libs/ardour/panner.cc @@ -75,6 +75,8 @@ StreamPanner::StreamPanner (Panner& p) { _muted = false; + parent.session().add_controllable (&_control); + x = 0.5; y = 0.5; z = 0.5; @@ -210,11 +212,6 @@ BaseStereoPanner::transport_stopped (nframes_t frame) _automation.reposition_for_rt_add (frame); if (_automation.automation_state() != Off) { - - if (_automation.automation_write()) { - _automation.save_state (_("automation write pass")); - } - set_position (_automation.eval (frame)); } } @@ -239,29 +236,6 @@ BaseStereoPanner::set_automation_state (AutoState state) } int -BaseStereoPanner::save (ostream& out) const -{ - LocaleGuard lg (X_("POSIX")); - - /* force a single format for numeric data to ease session interchange - across national boundaries. - */ - - out << "begin" << endl; - - for (AutomationList::const_iterator i = _automation.const_begin(); i != _automation.const_end(); ++i) { - out << '\t' << (nframes_t) floor ((*i)->when) << ' ' << (*i)->value << endl; - if (!out) { - error << string_compose (_("error writing pan automation file (%s)"), strerror (errno)) << endmsg; - return -1; - } - } - out << "end" << endl; - - return 0; -} - -int BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt) { char line[128]; @@ -270,7 +244,7 @@ BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt) _automation.clear (); while (in.getline (line, sizeof (line), '\n')) { - nframes_t when; + jack_nframes_t when; double value; ++linecnt; @@ -284,13 +258,12 @@ BaseStereoPanner::load (istream& in, string path, uint32_t& linecnt) continue; } - _automation.add (when, value, true); + _automation.fast_simple_add (when, value); } /* now that we are done loading */ - _automation.save_state (_("loaded from disk")); - _automation.StateChanged (Change (0)); + _automation.StateChanged (); return 0; } @@ -543,17 +516,13 @@ EqualPowerStereoPanner::state (bool full_state) snprintf (buf, sizeof (buf), "%.12g", x); root->add_property (X_("x"), buf); root->add_property (X_("type"), EqualPowerStereoPanner::name); - if (full_state) { - snprintf (buf, sizeof (buf), "0x%x", _automation.automation_state()); - } else { - /* never store automation states other than off in a template */ - snprintf (buf, sizeof (buf), "0x%x", ARDOUR::Off); - } - root->add_property (X_("automation-state"), buf); - snprintf (buf, sizeof (buf), "0x%x", _automation.automation_style()); - root->add_property (X_("automation-style"), buf); + + XMLNode* autonode = new XMLNode (X_("Automation")); + autonode->add_child_nocopy (_automation.state (full_state)); + root->add_child_nocopy (*autonode); StreamPanner::add_state (*root); + root->add_child_nocopy (_control.get_state ()); return *root; @@ -563,7 +532,6 @@ int EqualPowerStereoPanner::set_state (const XMLNode& node) { const XMLProperty* prop; - int x; float pos; LocaleGuard lg (X_("POSIX")); @@ -572,29 +540,24 @@ EqualPowerStereoPanner::set_state (const XMLNode& node) set_position (pos, true); } - if ((prop = node.property (X_("automation-state")))) { - sscanf (prop->value().c_str(), "0x%x", &x); - _automation.set_automation_state ((AutoState) x); - - if (x != Off) { - set_position (_automation.eval (parent.session().transport_frame())); - } - } - - if ((prop = node.property (X_("automation-style")))) { - sscanf (prop->value().c_str(), "0x%x", &x); - _automation.set_automation_style ((AutoStyle) x); - } - StreamPanner::set_state (node); for (XMLNodeConstIterator iter = node.children().begin(); iter != node.children().end(); ++iter) { + if ((*iter)->name() == X_("panner")) { + _control.set_state (**iter); - parent.session().add_controllable (&_control); + + } else if ((*iter)->name() == X_("Automation")) { + + _automation.set_state (*((*iter)->children().front())); + + if (_automation.automation_state() != Off) { + set_position (_automation.eval (parent.session().transport_frame())); + } } } - + return 0; } @@ -765,12 +728,6 @@ Multi2dPanner::load (istream& in, string path, uint32_t& linecnt) return 0; } -int -Multi2dPanner::save (ostream& out) const -{ - return 0; -} - XMLNode& Multi2dPanner::get_state (void) { @@ -790,6 +747,8 @@ Multi2dPanner::state (bool full_state) root->add_property (X_("y"), buf); root->add_property (X_("type"), Multi2dPanner::name); + /* XXX no meaningful automation yet */ + return *root; } @@ -827,6 +786,7 @@ Panner::Panner (string name, Session& s) : _session (s) { set_name (name); + _linked = false; _link_direction = SameDirection; _bypassed = false; @@ -857,17 +817,6 @@ Panner::set_link_direction (LinkDirection ld) } void -Panner::set_name (string str) -{ - automation_path = _session.automation_dir(); - automation_path += _session.snap_name(); - automation_path += "-pan-"; - automation_path += legalize_for_path (str); - automation_path += ".automation"; -} - - -void Panner::set_bypassed (bool yn) { if (yn != _bypassed) { @@ -883,7 +832,6 @@ Panner::reset (uint32_t nouts, uint32_t npans) uint32_t n; bool changed = false; - if (nouts < 2 || (nouts == outputs.size() && npans == size())) { return; } @@ -1095,102 +1043,6 @@ Panner::clear_automation () _session.set_dirty (); } -int -Panner::save () const -{ - ofstream out (automation_path.c_str()); - - if (!out) { - error << string_compose (_("cannot open pan automation file \"%1\" for saving (%2)"), automation_path, strerror (errno)) - << endmsg; - return -1; - } - - out << X_("version ") << current_automation_version_number << endl; - - for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) { - if ((*i)->save (out)) { - return -1; - } - } - - return 0; -} - -int -Panner::load () -{ - char line[128]; - uint32_t linecnt = 0; - float version; - iterator sp; - LocaleGuard lg (X_("POSIX")); - - if (automation_path.length() == 0) { - return 0; - } - - if (access (automation_path.c_str(), F_OK)) { - return 0; - } - - ifstream in (automation_path.c_str()); - - if (!in) { - error << string_compose (_("cannot open pan automation file %1 (%2)"), - automation_path, strerror (errno)) - << endmsg; - return -1; - } - - sp = begin(); - - while (in.getline (line, sizeof(line), '\n')) { - - if (++linecnt == 1) { - if (memcmp (line, X_("version"), 7) == 0) { - if (sscanf (line, "version %f", &version) != 1) { - error << string_compose(_("badly formed version number in pan automation event file \"%1\""), automation_path) << endmsg; - return -1; - } - } else { - error << string_compose(_("no version information in pan automation event file \"%1\" (first line = %2)"), - automation_path, line) << endmsg; - return -1; - } - - if (version != current_automation_version_number) { - error << string_compose(_("mismatched pan automation event file version (%1)"), version) << endmsg; - return -1; - } - - continue; - } - - if (strlen (line) == 0 || line[0] == '#') { - continue; - } - - if (strcmp (line, "begin") == 0) { - - if (sp == end()) { - error << string_compose (_("too many panner states found in pan automation file %1"), - automation_path) - << endmsg; - return -1; - } - - if ((*sp)->load (in, automation_path, linecnt)) { - return -1; - } - - ++sp; - } - } - - return 0; -} - struct PanPlugins { string name; uint32_t nouts; @@ -1215,10 +1067,6 @@ Panner::state (bool full) XMLNode* root = new XMLNode (X_("Panner")); char buf[32]; - for (iterator p = begin(); p != end(); ++p) { - root->add_child_nocopy ((*p)->state (full)); - } - root->add_property (X_("linked"), (_linked ? "yes" : "no")); snprintf (buf, sizeof (buf), "%d", _link_direction); root->add_property (X_("link_direction"), buf); @@ -1235,10 +1083,8 @@ Panner::state (bool full) root->add_child_nocopy (*onode); } - if (full) { - if (save () == 0) { - root->add_property (X_("automation"), Glib::path_get_basename (automation_path)); - } + for (vector<StreamPanner*>::const_iterator i = begin(); i != end(); ++i) { + root->add_child_nocopy ((*i)->state (full)); } return *root; @@ -1329,7 +1175,7 @@ Panner::set_state (const XMLNode& node) } } - /* don't try to load automation if it wasn't marked as existing */ + /* don't try to do old-school automation loading if it wasn't marked as existing */ if ((prop = node.property (X_("automation")))) { @@ -1629,3 +1475,83 @@ Panner::distribute (BufferSet& inbufs, BufferSet& outbufs, nframes_t start_frame } } +/* old school automation handling */ + +void +Panner::set_name (string str) +{ + automation_path = _session.automation_dir(); + automation_path += _session.snap_name(); + automation_path += "-pan-"; + automation_path += legalize_for_path (str); + automation_path += ".automation"; +} + +int +Panner::load () +{ + char line[128]; + uint32_t linecnt = 0; + float version; + iterator sp; + LocaleGuard lg (X_("POSIX")); + + if (automation_path.length() == 0) { + return 0; + } + + if (access (automation_path.c_str(), F_OK)) { + return 0; + } + + ifstream in (automation_path.c_str()); + + if (!in) { + error << string_compose (_("cannot open pan automation file %1 (%2)"), + automation_path, strerror (errno)) + << endmsg; + return -1; + } + + sp = begin(); + + while (in.getline (line, sizeof(line), '\n')) { + + if (++linecnt == 1) { + if (memcmp (line, X_("version"), 7) == 0) { + if (sscanf (line, "version %f", &version) != 1) { + error << string_compose(_("badly formed version number in pan automation event file \"%1\""), automation_path) << endmsg; + return -1; + } + } else { + error << string_compose(_("no version information in pan automation event file \"%1\" (first line = %2)"), + automation_path, line) << endmsg; + return -1; + } + + continue; + } + + if (strlen (line) == 0 || line[0] == '#') { + continue; + } + + if (strcmp (line, "begin") == 0) { + + if (sp == end()) { + error << string_compose (_("too many panner states found in pan automation file %1"), + automation_path) + << endmsg; + return -1; + } + + if ((*sp)->load (in, automation_path, linecnt)) { + return -1; + } + + ++sp; + } + } + + return 0; +} |