Do not try to restore Route solo state after clearing all solo state
[ardour.git] / gtk2_ardour / sfdb_ui.cc
index 6f6912abc9e28bb38af48e8b501838abaa4812a8..b2f96ed8a648c90db821f5e980ba2bb89d25e408 100644 (file)
@@ -21,7 +21,7 @@
 #include "gtk2ardour-config.h"
 #endif
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 #include <map>
 #include <cerrno>
@@ -33,7 +33,7 @@
 #include <gtkmm/box.h>
 #include <gtkmm/stock.h>
 
-#include <pbd/gstdio_compat.h>
+#include "pbd/gstdio_compat.h"
 #include <glibmm/fileutils.h>
 
 #include "pbd/convert.h"
@@ -303,7 +303,15 @@ SoundFileBox::setup_labels (const string& filename)
                tags_entry.set_sensitive (false);
 
                if (ms) {
-                       channels_value.set_text (to_string(ms->num_tracks(), std::dec));
+                       if (ms->is_type0()) {
+                               channels_value.set_text (to_string(ms->channels().size(), std::dec));
+                       } else {
+                               if (ms->num_tracks() > 1) {
+                                       channels_value.set_text (to_string(ms->num_tracks(), std::dec) + _("(Tracks)"));
+                               } else {
+                                       channels_value.set_text (to_string(ms->num_tracks(), std::dec));
+                               }
+                       }
                        length_clock.set (ms->length(ms->timeline_position()));
                } else {
                        channels_value.set_text ("");
@@ -560,18 +568,18 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
        , gm (0)
 {
 
-#ifdef GTKOSX
+#ifdef __APPLE__
        try {
                /* add_shortcut_folder throws an exception if the folder being added already has a shortcut */
                chooser.add_shortcut_folder_uri("file:///Library/GarageBand/Apple Loops");
                chooser.add_shortcut_folder_uri("file:///Library/Audio/Apple Loops");
                chooser.add_shortcut_folder_uri("file:///Library/Application Support/GarageBand/Instrument Library/Sampler/Sampler Files");
-               chooser.add_shortcut_folder_uri("file:///Volumes");
        }
        catch (Glib::Error & e) {
                std::cerr << "sfdb.add_shortcut_folder() threw Glib::Error " << e.what() << std::endl;
        }
 #endif
+       Gtkmm2ext::add_volume_shortcuts (chooser);
 
        //add the file chooser
 
@@ -597,7 +605,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
        chooser.signal_update_preview().connect(sigc::mem_fun(*this, &SoundFileBrowser::update_preview));
        chooser.signal_file_activated().connect (sigc::mem_fun (*this, &SoundFileBrowser::chooser_file_activated));
 
-#ifdef GTKOSX
+#ifdef __APPLE__
        /* some broken redraw behaviour - this is a bandaid */
        chooser.signal_selection_changed().connect (mem_fun (chooser, &Widget::queue_draw));
 #endif
@@ -647,6 +655,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
        notebook.append_page (*vbox, _("Search Tags"));
 
        //add freesound search
+#ifdef FREESOUND_GOT_FIXED
 
        HBox* passbox;
        Label* label;
@@ -721,6 +730,7 @@ SoundFileBrowser::SoundFileBrowser (string title, ARDOUR::Session* s, bool persi
        freesound_more_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_more_clicked));
        freesound_similar_btn.signal_clicked().connect(sigc::mem_fun(*this, &SoundFileBrowser::freesound_similar_clicked));
        notebook.append_page (*vbox, _("Search Freesound"));
+#endif
 
        notebook.set_size_request (500, -1);
        notebook.signal_switch_page().connect (sigc::hide_return (sigc::hide (sigc::hide (sigc::mem_fun (*this, &SoundFileBrowser::reset_options)))));
@@ -832,7 +842,7 @@ SoundFileBrowser::add_gain_meter ()
 
        boost::shared_ptr<Route> r = _session->the_auditioner ();
 
-       gm->set_controls (r, r->shared_peak_meter(), r->amp());
+       gm->set_controls (r, r->shared_peak_meter(), r->amp(), r->gain_control());
        gm->set_fader_name (X_("GainFader"));
 
        meter_packer.set_border_width (12);
@@ -1091,7 +1101,7 @@ SoundFileBrowser::freesound_search()
        std::string theString = mootcher.searchText(
                        search_string,
                        freesound_page,
-#ifdef GTKOSX
+#ifdef __APPLE__
                        "", // OSX eats anything incl mp3
 #else
                        "type:wav OR type:aiff OR type:flac OR type:aif OR type:ogg OR type:oga",
@@ -1293,6 +1303,11 @@ SoundFileOmega::reset_options_noret ()
 bool
 SoundFileOmega::reset_options ()
 {
+       if (_import_active) {
+               _reset_post_import = true;
+               return true;
+       }
+
        vector<string> paths = get_paths ();
 
        if (paths.empty()) {
@@ -1421,6 +1436,7 @@ SoundFileOmega::reset_options ()
        vector<string> channel_strings;
 
        if (mode == ImportAsTrack || mode == ImportAsTapeTrack || mode == ImportToTrack) {
+               /// XXX needs special casing for MIDI type-1 files
                channel_strings.push_back (_("one track per file"));
 
                if (selection_includes_multichannel) {
@@ -1564,7 +1580,17 @@ SoundFileOmega::check_info (const vector<string>& paths, bool& same_size, bool&
                        Evoral::SMF reader;
                        reader.open(*i);
                        if (reader.num_tracks() > 1) {
-                               multichannel = true; // "channel" == track here...
+                               /* NOTE: we cannot merge midi-tracks.
+                                * they will always be on separate tracks
+                                * "one track per file" is not possible.
+                                */
+                               //multichannel = true; // "channel" == track here...
+                       }
+                       if (reader.is_type0 () && reader.channels().size() > 1) {
+                               /* for type-0 files, we can split
+                                * "one track per channel"
+                                */
+                               multichannel = true;
                        }
 
                        /* XXX we need err = true handling here in case
@@ -1664,64 +1690,58 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s,
        , copy_files_btn ( _("Copy files to session"))
        , selected_audio_track_cnt (selected_audio_tracks)
        , selected_midi_track_cnt (selected_midi_tracks)
+       , _import_active (false)
+       , _reset_post_import (false)
 {
-       VBox* vbox;
-       HBox* hbox;
        vector<string> str;
 
-       set_size_request (-1, 450);
+       set_size_request (-1, 550);
 
        block_two.set_border_width (12);
        block_three.set_border_width (12);
        block_four.set_border_width (12);
 
-       options.set_spacing (12);
-
        str.clear ();
        str.push_back (_("file timestamp"));
        str.push_back (_("edit point"));
        str.push_back (_("playhead"));
        str.push_back (_("session start"));
        set_popdown_strings (where_combo, str);
-       where_combo.set_active_text (str.front());
+       where_combo.set_active_text (str.back());
        where_combo.signal_changed().connect (sigc::mem_fun (*this, &SoundFileOmega::where_combo_changed));
 
        Label* l = manage (new Label);
-       l->set_markup (_("<b>Add files as ...</b>"));
-
-       vbox = manage (new VBox);
-       vbox->set_border_width (12);
-       vbox->set_spacing (6);
-       vbox->pack_start (*l, false, false);
-       vbox->pack_start (action_combo, false, false);
-       hbox = manage (new HBox);
-       hbox->pack_start (*vbox, false, false);
-       options.pack_start (*hbox, false, false);
+       l->set_markup (_("<b>Add files ...</b>"));
+       options.attach (*l, 0, 1, 0, 1, FILL, SHRINK, 8, 0);
+       options.attach (action_combo, 0, 1, 1, 2, FILL, SHRINK, 8, 0);
 
        l = manage (new Label);
        l->set_markup (_("<b>Insert at</b>"));
+       options.attach (*l, 0, 1, 3, 4, FILL, SHRINK, 8, 0);
+       options.attach (where_combo, 0, 1, 4, 5, FILL, SHRINK, 8, 0);
 
-       vbox = manage (new VBox);
-       vbox->set_border_width (12);
-       vbox->set_spacing (6);
-       vbox->pack_start (*l, false, false);
-       vbox->pack_start (where_combo, false, false);
-       hbox = manage (new HBox);
-       hbox->pack_start (*vbox, false, false);
-       options.pack_start (*hbox, false, false);
+       l = manage (new Label);
+       l->set_markup (_("<b>Mapping</b>"));
+       options.attach (*l, 1, 2, 0, 1, FILL, SHRINK, 8, 0);
+       options.attach (channel_combo, 1, 2, 1, 2, FILL, SHRINK, 8, 0);
 
+       l = manage (new Label);
+       l->set_markup (_("<b>Conversion quality</b>"));
+       options.attach (*l, 1, 2, 3, 4, FILL, SHRINK, 8, 0);
+       options.attach (src_combo, 1, 2, 4, 5, FILL, SHRINK, 8, 0);
 
        l = manage (new Label);
-       l->set_markup (_("<b>Mapping</b>"));
+       l->set_markup (_("<b>Instrument</b>"));
+       options.attach (*l, 3, 4, 0, 1, FILL, SHRINK, 8, 0);
+       options.attach (instrument_combo, 3, 4, 1, 2, FILL, SHRINK, 8, 0);
 
-       vbox = manage (new VBox);
-       vbox->set_border_width (12);
-       vbox->set_spacing (6);
-       vbox->pack_start (*l, false, false);
-       vbox->pack_start (channel_combo, false, false);
-       hbox = manage (new HBox);
-       hbox->pack_start (*vbox, false, false);
-       options.pack_start (*hbox, false, false);
+       Alignment *hspace = manage (new Alignment ());
+       hspace->set_size_request (2, 2);
+       options.attach (*hspace, 0, 3, 2, 3, FILL, SHRINK, 0, 8);
+
+       Alignment *vspace = manage (new Alignment ());
+       vspace->set_size_request (2, 2);
+       options.attach (*vspace, 2, 3, 0, 3, EXPAND, SHRINK, 0, 0);
 
        str.clear ();
        str.push_back (_("one track per file"));
@@ -1729,30 +1749,6 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s,
        channel_combo.set_active_text (str.front());
        channel_combo.set_sensitive (false);
 
-       l = manage (new Label);
-       l->set_markup (_("<b>Conversion quality</b>"));
-
-       vbox = manage (new VBox);
-       vbox->set_border_width (12);
-       vbox->set_spacing (6);
-       vbox->pack_start (*l, false, false);
-       vbox->pack_start (src_combo, false, false);
-       hbox = manage (new HBox);
-       hbox->pack_start (*vbox, false, false);
-       options.pack_start (*hbox, false, false);
-
-       l = manage (new Label);
-       l->set_markup (_("<b>Instrument</b>"));
-
-       vbox = manage (new VBox);
-       vbox->set_border_width (12);
-       vbox->set_spacing (6);
-       vbox->pack_start (*l, false, false);
-       vbox->pack_start (instrument_combo, false, false);
-       hbox = manage (new HBox);
-       hbox->pack_start (*vbox, false, false);
-       options.pack_start (*hbox, false, false);
-
        str.clear ();
        str.push_back (_("Best"));
        str.push_back (_("Good"));
@@ -1778,10 +1774,9 @@ SoundFileOmega::SoundFileOmega (string title, ARDOUR::Session* s,
        }
 
        block_four.pack_start (copy_files_btn, false, false);
+       options.attach (block_four, 3, 4, 4, 5, FILL, SHRINK, 8, 0);
 
-       options.pack_start (block_four, false, false);
-
-       vpacker.pack_start (options, false, false);
+       vpacker.pack_start (options, false, true);
 
        /* setup disposition map */
 
@@ -1977,10 +1972,19 @@ SoundFileOmega::do_something (int action)
 
        SrcQuality quality = get_src_quality();
 
+       _import_active = true;
+
        if (copy_files_btn.get_active()) {
                PublicEditor::instance().do_import (paths, chns, mode, quality, where, instrument);
        } else {
                PublicEditor::instance().do_embed (paths, chns, mode, where, instrument);
        }
+
+       _import_active = false;
+
+       if (_reset_post_import) {
+               _reset_post_import = false;
+               reset_options ();
+       }
 }