move TimecodeFormat to libtimecode
[ardour.git] / gtk2_ardour / session_option_editor.cc
index 06ad58d7e0949d3d7cabc81139582fa142a6b9f7..b21e76c14090e79ca589d0765cac190c0df20117 100644 (file)
+/*
+    Copyright (C) 2000-2010 Paul Davis
+
+    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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include "ardour/session.h"
-#include "ardour/io.h"
-#include "ardour/auditioner.h"
-#include "ardour/audioengine.h"
-#include "ardour/port.h"
 
 #include "gui_thread.h"
 #include "session_option_editor.h"
-#include "port_matrix.h"
+#include "search_path_option.h"
 #include "i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
-
-class OptionsPortMatrix : public PortMatrix
-{
-public:
-       OptionsPortMatrix (Gtk::Window* parent, ARDOUR::Session* session)
-               : PortMatrix (parent, session, DataType::AUDIO)
-       {
-               _port_group.reset (new PortGroup (""));
-               _ports[OURS].add_group (_port_group);
-
-               setup_all_ports ();
-               init ();
-       }
-
-       void setup_ports (int dim)
-       {
-               if (dim == OURS) {
-                       _port_group->clear ();
-                       _port_group->add_bundle (_session->click_io()->bundle());
-                       _port_group->add_bundle (_session->the_auditioner()->output()->bundle());
-               } else {
-                       _ports[OTHER].gather (_session, DataType::AUDIO, true, false);
-               }
-       }
-
-       void set_state (ARDOUR::BundleChannel c[2], bool s)
-       {
-               Bundle::PortList const & our_ports = c[OURS].bundle->channel_ports (c[OURS].channel);
-               Bundle::PortList const & other_ports = c[OTHER].bundle->channel_ports (c[OTHER].channel);
-
-               if (c[OURS].bundle == _session->click_io()->bundle()) {
-
-                       for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
-                               for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
-
-                                       Port* f = _session->engine().get_port_by_name (*i);
-                                       assert (f);
-
-                                       if (s) {
-                                               _session->click_io()->connect (f, *j, 0);
-                                       } else {
-                                               _session->click_io()->disconnect (f, *j, 0);
-                                       }
-                               }
-                       }
-               }
-       }
-
-       PortMatrixNode::State get_state (ARDOUR::BundleChannel c[2]) const
-       {
-               Bundle::PortList const & our_ports = c[OURS].bundle->channel_ports (c[OURS].channel);
-               Bundle::PortList const & other_ports = c[OTHER].bundle->channel_ports (c[OTHER].channel);
-
-               if (c[OURS].bundle == _session->click_io()->bundle()) {
-
-                       for (ARDOUR::Bundle::PortList::const_iterator i = our_ports.begin(); i != our_ports.end(); ++i) {
-                               for (ARDOUR::Bundle::PortList::const_iterator j = other_ports.begin(); j != other_ports.end(); ++j) {
-                                       Port* f = _session->engine().get_port_by_name (*i);
-                                       assert (f);
-
-                                       if (f->connected_to (*j)) {
-                                               return PortMatrixNode::ASSOCIATED;
-                                       } else {
-                                               return PortMatrixNode::NOT_ASSOCIATED;
-                                       }
-                               }
-                       }
-
-               } else {
-
-                       /* XXX */
-
-               }
-
-               return PortMatrixNode::NOT_ASSOCIATED;
-       }
-
-       bool list_is_global (int dim) const {
-               return (dim == OTHER);
-       }
-
-       bool can_remove_channels (boost::shared_ptr<Bundle>) const {
-               return false;
-       }
-
-       void remove_channel (ARDOUR::BundleChannel) {}
-
-       std::string disassociation_verb () const {
-               return _("Disassociate");
-       }
-
-private:
-       /* see PortMatrix: signal flow from 0 to 1 (out to in) */
-       enum {
-               OURS = 0,
-               OTHER = 1,
-       };
-
-       boost::shared_ptr<PortGroup> _port_group;
-
-};
-
-
-class ConnectionOptions : public OptionEditorBox
-{
-public:
-       ConnectionOptions (Gtk::Window* parent, ARDOUR::Session* s)
-               : _port_matrix (parent, s)
-       {
-               _box->pack_start (_port_matrix);
-       }
-
-       void parameter_changed (string const &)
-       {
-
-       }
-
-       void set_state_from_config ()
-       {
-
-       }
-
-private:
-       OptionsPortMatrix _port_matrix;
-};
+using namespace Timecode;
 
 SessionOptionEditor::SessionOptionEditor (Session* s)
        : OptionEditor (&(s->config), _("Session Properties"))
        , _session_config (&(s->config))
 {
-        set_name ("SessionProperties");
+       set_session (s);
 
-       /* SYNC */
-
-       ComboOption<uint32_t>* spf = new ComboOption<uint32_t> (
-               "subframes-per-frame",
-               _("Subframes per frame"),
-               sigc::mem_fun (*_session_config, &SessionConfiguration::get_subframes_per_frame),
-               sigc::mem_fun (*_session_config, &SessionConfiguration::set_subframes_per_frame)
-               );
-
-       spf->add (80, _("80"));
-       spf->add (100, _("100"));
-
-       add_option (_("Sync"), spf);
-
-       ComboOption<SyncSource>* ssrc = new ComboOption<SyncSource> (
-               "sync-source",
-               _("External sync source"),
-               sigc::mem_fun (*_session_config, &SessionConfiguration::get_sync_source),
-               sigc::mem_fun (*_session_config, &SessionConfiguration::set_sync_source)
-               );
-       
-       s->MTC_PortChanged.connect (_session_connections, invalidator (*this), boost::bind (&SessionOptionEditor::populate_sync_options, this, s, ssrc), gui_context());
-       s->MIDIClock_PortChanged.connect (_session_connections, invalidator (*this), boost::bind (&SessionOptionEditor::populate_sync_options, this, s, ssrc), gui_context());
-       s->config.ParameterChanged.connect (_session_connections, invalidator (*this), ui_bind (&SessionOptionEditor::follow_sync_state, this, _1, s, ssrc), gui_context());
+        set_name ("SessionProperties");
 
-       populate_sync_options (s, ssrc);
-       follow_sync_state (string ("external-sync"), s, ssrc);
+       /* TIMECODE*/
 
-       add_option (_("Sync"), ssrc);
+       add_option (_("Timecode"), new OptionEditorHeading (_("Timecode Settings")));
 
        ComboOption<TimecodeFormat>* smf = new ComboOption<TimecodeFormat> (
                "timecode-format",
@@ -191,14 +58,19 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
        smf->add (timecode_5994, _("59.94"));
        smf->add (timecode_60, _("60"));
 
-       add_option (_("Sync"), smf);
+       add_option (_("Timecode"), smf);
 
-       add_option (_("Sync"), new BoolOption (
-                           "timecode-source-is-synced",
-                           _("Timecode source shares sample clock with audio interface"),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_source_is_synced),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_source_is_synced)
-                           ));
+       ComboOption<uint32_t>* spf = new ComboOption<uint32_t> (
+               "subframes-per-frame",
+               _("Subframes per frame"),
+               sigc::mem_fun (*_session_config, &SessionConfiguration::get_subframes_per_frame),
+               sigc::mem_fun (*_session_config, &SessionConfiguration::set_subframes_per_frame)
+               );
+
+       spf->add (80, _("80"));
+       spf->add (100, _("100"));
+
+       add_option (_("Timecode"), spf);
 
        ComboOption<float>* vpu = new ComboOption<float> (
                "video-pullup",
@@ -217,7 +89,34 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
        vpu->add (-4.1667, _("-4.1667"));
        vpu->add (-4.1667 - 0.1, _("-4.1667 - 0.1%"));
 
-       add_option (_("Sync"), vpu);
+       add_option (_("Timecode"), vpu);
+
+       ClockOption* co = new ClockOption (
+               "timecode-offset",
+               _("Timecode offset"),
+               sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_offset),
+               sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_offset)
+               );
+
+       co->set_session (_session);
+
+       add_option (_("Timecode"), co);
+
+       add_option (_("Timecode"), new BoolOption (
+                           "timecode-offset-negative",
+                           _("Timecode Offset Negative"),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_timecode_offset_negative),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_timecode_offset_negative)
+                           ));
+
+       add_option (_("Timecode"), new OptionEditorHeading (_("JACK Transport/Time Settings")));
+
+       add_option (_("Timecode"), new BoolOption (
+                           "jack-time-master",
+                           string_compose (_("%1 is JACK Time Master (provides Bar|Beat|Tick and other information to JACK)"), PROGRAM_NAME),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_jack_time_master),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_jack_time_master)
+                           ));
 
        /* FADES */
 
@@ -233,6 +132,19 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
 
        add_option (_("Fades"), cfm);
 
+       ComboOption<CrossfadeChoice>* cfc = new ComboOption<CrossfadeChoice> (
+               "xfade-choice",
+               _("Crossfade type"),
+               sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfade_choice),
+               sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfade_choice)
+               );
+
+       cfc->add (ConstantPowerMinus3dB, _("constant power (-3dB)"));
+       cfc->add (ConstantPowerMinus6dB, _("constant power (-6dB)"));
+       cfc->add (RegionFades, _("use existing region fade shape"));
+
+       add_option (_("Fades"), cfc);
+
        add_option (_("Fades"), new SpinOption<float> (
                _("short-xfade-seconds"),
                _("Short crossfade length"),
@@ -258,20 +170,6 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
                            sigc::mem_fun (*_session_config, &SessionConfiguration::set_auto_xfade)
                            ));
 
-        add_option (_("Fades"), new BoolOption (
-                           "xfades-active",
-                           _("Crossfades active"),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfades_active),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfades_active)
-                           ));
-
-       add_option (_("Fades"), new BoolOption (
-                           "xfades-visible",
-                           _("Crossfades visible"),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_xfades_visible),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_xfades_visible)
-                           ));
-
        add_option (_("Fades"), new BoolOption (
                            "use-region-fades",
                            _("Region fades active"),
@@ -286,9 +184,9 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
                            sigc::mem_fun (*_session_config, &SessionConfiguration::set_show_region_fades)
                            ));
 
-       /* MISC */
+       /* Media */
 
-       add_option (_("Misc"), new OptionEditorHeading (_("Audio file format")));
+       add_option (_("Media"), new OptionEditorHeading (_("Audio file format")));
 
        ComboOption<SampleFormat>* sf = new ComboOption<SampleFormat> (
                "native-file-data-format",
@@ -301,7 +199,7 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
        sf->add (FormatInt24, _("24-bit integer"));
        sf->add (FormatInt16, _("16-bit integer"));
 
-       add_option (_("Misc"), sf);
+       add_option (_("Media"), sf);
 
        ComboOption<HeaderFormat>* hf = new ComboOption<HeaderFormat> (
                "native-file-header-format",
@@ -315,83 +213,107 @@ SessionOptionEditor::SessionOptionEditor (Session* s)
        hf->add (WAVE64, _("WAVE-64"));
        hf->add (CAF, _("CAF"));
 
-       add_option (_("Misc"), hf);
+       add_option (_("Media"), hf);
 
-       add_option (_("Misc"), new OptionEditorHeading (_("Layering")));
+       add_option (_("Media"), new OptionEditorHeading (_("File locations")));
 
-       ComboOption<LayerModel>* lm = new ComboOption<LayerModel> (
-               "layer-model",
-               _("Layering model in overlaid mode"),
-               sigc::mem_fun (*_session_config, &SessionConfiguration::get_layer_model),
-               sigc::mem_fun (*_session_config, &SessionConfiguration::set_layer_model)
-               );
+        SearchPathOption* spo = new SearchPathOption ("audio-search-path", _("Search for audio files in:"),
+                                                      sigc::mem_fun (*_session_config, &SessionConfiguration::get_audio_search_path),
+                                                      sigc::mem_fun (*_session_config, &SessionConfiguration::set_audio_search_path));
+        add_option (_("Media"), spo);
+
+        spo = new SearchPathOption ("midi-search-path", _("Search for MIDI files in:"),
+                                    sigc::mem_fun (*_session_config, &SessionConfiguration::get_midi_search_path),
+                                    sigc::mem_fun (*_session_config, &SessionConfiguration::set_midi_search_path));
 
-       lm->add (LaterHigher, _("later is higher"));
-       lm->add (MoveAddHigher, _("most recently moved or added is higher"));
-       lm->add (AddHigher, _("most recently added is higher"));
+        add_option (_("Media"), spo);
 
-       add_option (_("Misc"), lm);
+       /* Monitoring */
 
-       add_option (_("Misc"), new OptionEditorHeading (_("MIDI Note Overlaps")));
+        add_option (_("Monitoring"), new BoolOption (
+                           "auto-input",
+                           _("Monitoring automatically follows transport state (\"auto-input\")"),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_auto_input),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_auto_input)
+                           ));
+
+        add_option (_("Monitoring"), new BoolOption (
+                           "have-monitor-section",
+                           _("Use monitor section in this session"),
+                           sigc::mem_fun (*this, &SessionOptionEditor::get_use_monitor_section),
+                           sigc::mem_fun (*this, &SessionOptionEditor::set_use_monitor_section)
+                           ));
+
+        /* Misc */
+
+       add_option (_("Misc"), new OptionEditorHeading (_("MIDI Options")));
+
+        add_option (_("Misc"), new BoolOption (
+                           "midi-copy-is-fork",
+                           _("MIDI region copies are independent"),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_midi_copy_is_fork),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_midi_copy_is_fork)
+                           ));
 
        ComboOption<InsertMergePolicy>* li = new ComboOption<InsertMergePolicy> (
                "insert-merge-policy",
-               _("Handle same note+channel overlaps by"),
+               _("Policy for handling overlapping notes\n on the same MIDI channel"),
                sigc::mem_fun (*_session_config, &SessionConfiguration::get_insert_merge_policy),
                sigc::mem_fun (*_session_config, &SessionConfiguration::set_insert_merge_policy)
                );
 
-        li->add (InsertMergeReject, _("Never allowing them"));
-        li->add (InsertMergeRelax, _("Don't do anything in particular"));
-        li->add (InsertMergeReplace, _("Replace any overlapped existing note"));
-        li->add (InsertMergeTruncateExisting, _("Shorten the overlapped existing note"));
-        li->add (InsertMergeTruncateAddition, _("Shorten the overlapping new note"));
-        li->add (InsertMergeExtend, _("Replace both overlapping notes with a single note"));
+        li->add (InsertMergeReject, _("never allow them"));
+        li->add (InsertMergeRelax, _("don't do anything in particular"));
+        li->add (InsertMergeReplace, _("replace any overlapped existing note"));
+        li->add (InsertMergeTruncateExisting, _("shorten the overlapped existing note"));
+        li->add (InsertMergeTruncateAddition, _("shorten the overlapping new note"));
+        li->add (InsertMergeExtend, _("replace both overlapping notes with a single note"));
 
        add_option (_("Misc"), li);
 
-       add_option (_("Misc"), new OptionEditorHeading (_("Broadcast WAVE metadata")));
+       add_option (_("Misc"), new OptionEditorHeading (_("Glue to bars and beats")));
 
-       add_option (_("Misc"), new EntryOption (
-                           "bwf-country-code",
-                           _("Country code"),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_bwf_country_code),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_bwf_country_code)
+       add_option (_("Misc"), new BoolOption (
+                           "glue-new-markers-to-bars-and-beats",
+                           _("Glue new markers to bars and beats"),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_glue_new_markers_to_bars_and_beats),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_glue_new_markers_to_bars_and_beats)
                            ));
 
-       add_option (_("Misc"), new EntryOption (
-                           "bwf-organization-code",
-                           _("Organization code"),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_bwf_organization_code),
-                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_bwf_organization_code)
+       add_option (_("Misc"), new BoolOption (
+                           "glue-new-regions-to-bars-and-beats",
+                           _("Glue new regions to bars and beats"),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::get_glue_new_regions_to_bars_and_beats),
+                           sigc::mem_fun (*_session_config, &SessionConfiguration::set_glue_new_regions_to_bars_and_beats)
                            ));
-
-       add_option (_("Connections"), new ConnectionOptions (this, s));
 }
 
 void
-SessionOptionEditor::populate_sync_options (Session* s, Option* opt)
+SessionOptionEditor::parameter_changed (std::string const & p)
 {
-       ComboOption<SyncSource>* sync_opt = dynamic_cast<ComboOption<SyncSource>* > (opt);
+       OptionEditor::parameter_changed (p);
+}
 
-       vector<SyncSource> sync_opts = s->get_available_sync_options ();
+/* the presence of absence of a monitor section is not really a regular session
+ * property so we provide these two functions to act as setter/getter slots
+ */
 
-       sync_opt->clear ();
+bool
+SessionOptionEditor::set_use_monitor_section (bool yn)
+{
+       bool had_monitor_section = _session->monitor_out();
 
-       for (vector<SyncSource>::iterator i = sync_opts.begin(); i != sync_opts.end(); ++i) {
-               sync_opt->add (*i, sync_source_to_string (*i));
+       if (yn) {
+               _session->add_monitor_section ();
+       } else {
+               _session->remove_monitor_section ();
        }
+
+       return had_monitor_section != yn;
 }
 
-void
-SessionOptionEditor::follow_sync_state (std::string p, Session* s, Option* opt)
+bool
+SessionOptionEditor::get_use_monitor_section ()
 {
-       ComboOption<SyncSource>* sync_opt = dynamic_cast<ComboOption<SyncSource>* > (opt);
-       if (p == "external-sync") {
-               if (s->config.get_external_sync()) {
-                       sync_opt->set_sensitive (false);
-               } else {
-                       sync_opt->set_sensitive (true);
-               }
-       }
+       return _session->monitor_out() != 0;
 }