/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2550 by schoenebeck, Wed May 14 01:31:30 2014 UTC revision 2553 by schoenebeck, Wed May 14 19:57:56 2014 UTC
# Line 40  Line 40 
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
45  #include "mainwindow.h"  #include "mainwindow.h"
46  #include "Settings.h"  #include "Settings.h"
# Line 202  MainWindow::MainWindow() : Line 203  MainWindow::MainWindow() :
203          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
204      );      );
205    
206        actionGroup->add(
207            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
208            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
209        );
210    
211    
212      // sample right-click popup actions      // sample right-click popup actions
213      actionGroup->add(      actionGroup->add(
# Line 256  MainWindow::MainWindow() : Line 262  MainWindow::MainWindow() :
262          "    </menu>"          "    </menu>"
263          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
264          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
265            "      <menuitem action='MergeFiles'/>"
266          "    </menu>"          "    </menu>"
267          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
268          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
# Line 309  MainWindow::MainWindow() : Line 316  MainWindow::MainWindow() :
316              uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));              uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
317          item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));          item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
318      }      }
319        {
320            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
321                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
322            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
323        }
324        {
325            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
326                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
327            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
328        }
329    
330    
331      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
332          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
# Line 626  void MainWindow::__clear() { Line 644  void MainWindow::__clear() {
644      set_file_is_shared(false);      set_file_is_shared(false);
645  }  }
646    
647    void MainWindow::__refreshEntireGUI() {
648        // clear the samples and instruments tree views
649        m_refTreeModel->clear();
650        m_refSamplesTreeModel->clear();
651        // remove all entries from "Instrument" menu
652        while (!instrument_menu->get_children().empty()) {
653            remove_instrument_from_menu(0);
654        }
655    
656        if (!this->file) return;
657    
658        load_gig(
659            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
660        );
661    }
662    
663  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
664  {  {
665      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 2130  void MainWindow::on_action_combine_instr Line 2164  void MainWindow::on_action_combine_instr
2164      delete d;      delete d;
2165  }  }
2166    
2167    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2168        struct _Source {
2169            std::vector<RIFF::File*> riffs;
2170            std::vector<gig::File*> gigs;
2171            
2172            ~_Source() {
2173                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2174                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2175                riffs.clear();
2176                gigs.clear();
2177            }
2178        } sources;
2179    
2180        if (filenames.empty())
2181            throw RIFF::Exception(_("No files selected, so nothing done."));
2182    
2183        // first open all input files (to avoid output file corruption)
2184        int i;
2185        try {
2186            for (i = 0; i < filenames.size(); ++i) {
2187                const std::string& filename = filenames[i];
2188                printf("opening file=%s\n", filename.c_str());
2189    
2190                RIFF::File* riff = new RIFF::File(filename);
2191                sources.riffs.push_back(riff);
2192    
2193                gig::File* gig = new gig::File(riff);
2194                sources.gigs.push_back(gig);
2195            }
2196        } catch (RIFF::Exception e) {
2197            throw RIFF::Exception(
2198                _("Error occurred while opening '") +
2199                filenames[i] +
2200                "': " +
2201                e.Message
2202            );
2203        } catch (...) {
2204            throw RIFF::Exception(
2205                _("Unknown exception occurred while opening '") +
2206                filenames[i] + "'"
2207            );
2208        }
2209    
2210        // now merge the opened .gig files to the main .gig file currently being
2211        // open in gigedit
2212        try {
2213            for (i = 0; i < filenames.size(); ++i) {
2214                const std::string& filename = filenames[i];
2215                printf("merging file=%s\n", filename.c_str());
2216                assert(i < sources.gigs.size());
2217    
2218                this->file->AddContentOf(sources.gigs[i]);
2219            }
2220        } catch (RIFF::Exception e) {
2221            throw RIFF::Exception(
2222                _("Error occurred while merging '") +
2223                filenames[i] +
2224                "': " +
2225                e.Message
2226            );
2227        } catch (...) {
2228            throw RIFF::Exception(
2229                _("Unknown exception occurred while merging '") +
2230                filenames[i] + "'"
2231            );
2232        }
2233    
2234        // Note: requires that this file already has a filename !
2235        this->file->Save();
2236    }
2237    
2238    void MainWindow::on_action_merge_files() {
2239        if (this->file->GetFileName().empty()) {
2240            Glib::ustring txt = _(
2241                "You seem to have a new .gig file open that has not been saved "
2242                "yet. You must save it somewhere before starting to merge it with "
2243                "other .gig files though, because during the merge operation the "
2244                "other files' sample data must be written on file level to the "
2245                "target .gig file."
2246            );
2247            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2248            msg.run();
2249            return;
2250        }
2251    
2252        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2253        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2254        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2255        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2256    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2257        Gtk::FileFilter filter;
2258        filter.add_pattern("*.gig");
2259    #else
2260        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2261        filter->add_pattern("*.gig");
2262    #endif
2263        dialog.set_filter(filter);
2264        if (current_gig_dir != "") {
2265            dialog.set_current_folder(current_gig_dir);
2266        }
2267        dialog.set_select_multiple(true);
2268    
2269        // show warning in the file picker dialog
2270        Gtk::HBox descriptionArea;
2271        descriptionArea.set_spacing(15);
2272        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2273        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2274    #if GTKMM_MAJOR_VERSION < 3
2275        view::WrapLabel description;
2276    #else
2277        Gtk::Label description;
2278        description.set_line_wrap();
2279    #endif
2280        description.set_markup(_(
2281            "\nSelect at least one .gig file that shall be merged to the .gig file "
2282            "currently being open in gigedit.\n\n"
2283            "<b>Please Note:</b> Merging with other files will modify your "
2284            "currently open .gig file on file level! And be aware that the current "
2285            "merge algorithm does not detect duplicate samples yet. So if you are "
2286            "merging files which are using equivalent sample data, those "
2287            "equivalent samples will currently be treated as separate samples and "
2288            "will accordingly be stored separately in the target .gig file!"
2289        ));
2290        descriptionArea.pack_start(description);
2291        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2292        descriptionArea.show_all();
2293    
2294        if (dialog.run() == Gtk::RESPONSE_OK) {
2295            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2296            std::vector<std::string> filenames = dialog.get_filenames();
2297    
2298            // merge the selected files to the currently open .gig file
2299            try {
2300                mergeFiles(filenames);
2301            } catch (RIFF::Exception e) {
2302                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2303                msg.run();
2304            }
2305    
2306            // update GUI
2307            __refreshEntireGUI();        
2308        }
2309    }
2310    
2311  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2312      this->file_is_shared = b;      this->file_is_shared = b;
2313    

Legend:
Removed from v.2550  
changed lines
  Added in v.2553

  ViewVC Help
Powered by ViewVC