+void
+Amp::set_gain (gain_t val, void *src)
+{
+ val = min (val, max_gain_coefficient);
+
+ if (src != _gain_control.get()) {
+ _gain_control->set_value (val);
+ // bit twisty, this will come back and call us again
+ // (this keeps control in sync with reality)
+ return;
+ }
+
+ _gain_control->set_double (val);
+ _session.set_dirty();
+}
+
+XMLNode&
+Amp::state (bool full_state)
+{
+ XMLNode& node (Processor::state (full_state));
+ node.add_property("type", "amp");
+ node.add_child_nocopy (_gain_control->get_state());
+
+ return node;
+}
+
+int
+Amp::set_state (const XMLNode& node, int version)
+{
+ XMLNode* gain_node;
+
+ Processor::set_state (node, version);
+
+ if ((gain_node = node.child (Controllable::xml_node_name.c_str())) != 0) {
+ _gain_control->set_state (*gain_node, version);
+ }
+
+ return 0;
+}
+
+void
+Amp::GainControl::set_value (double val)
+{
+ if (val > max_gain_coefficient) {
+ val = max_gain_coefficient;
+ }
+
+ _amp->set_gain (val, this);
+
+ AutomationControl::set_value(val);
+}
+
+double
+Amp::GainControl::internal_to_interface (double v) const
+{
+ return gain_to_slider_position (v);
+}
+
+double
+Amp::GainControl::interface_to_internal (double v) const
+{
+ return slider_position_to_gain (v);
+}
+
+double
+Amp::GainControl::internal_to_user (double v) const
+{
+ return accurate_coefficient_to_dB (v);
+}
+
+/** Write gain automation for this cycle into the buffer previously passed in to
+ * set_gain_automation_buffer (if we are in automation playback mode and the
+ * transport is rolling).
+ */
+void
+Amp::setup_gain_automation (framepos_t start_frame, framepos_t end_frame, framecnt_t nframes)
+{
+ Glib::Threads::Mutex::Lock am (control_lock(), Glib::Threads::TRY_LOCK);
+
+ if (am.locked() && _session.transport_rolling() && _gain_control->automation_playback()) {
+ assert (_gain_automation_buffer);
+ _apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
+ start_frame, end_frame, _gain_automation_buffer, nframes);
+ } else {
+ _apply_gain_automation = false;
+ }
+}
+
+bool
+Amp::visible() const
+{
+ return true;
+}
+
+std::string
+Amp::value_as_string (boost::shared_ptr<AutomationControl> ac) const
+{
+ if (ac == _gain_control) {
+ char buffer[32];
+ snprintf (buffer, sizeof (buffer), "%.2fdB", ac->internal_to_user (ac->get_value ()));
+ return buffer;
+ }