/[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 2541 by schoenebeck, Wed Apr 23 16:49:05 2014 UTC revision 2579 by persson, Sat May 24 06:44:39 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"
47    #include "CombineInstrumentsDialog.h"
48  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
49  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
50    
# Line 194  MainWindow::MainWindow() : Line 196  MainWindow::MainWindow() :
196      );      );
197    
198    
199        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
200    
201        actionGroup->add(
202            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
203            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(
214          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 245  MainWindow::MainWindow() : Line 260  MainWindow::MainWindow() :
260          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
261          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
262          "    </menu>"          "    </menu>"
263            "    <menu action='MenuTools'>"
264            "      <menuitem action='CombineInstruments'/>"
265            "      <menuitem action='MergeFiles'/>"
266            "    </menu>"
267          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
268          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
269          "    </menu>"          "    </menu>"
# Line 297  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 422  MainWindow::MainWindow() : Line 452  MainWindow::MainWindow() :
452    
453      // start with a new gig file by default      // start with a new gig file by default
454      on_action_file_new();      on_action_file_new();
455    
456        // select 'Instruments' tab by default
457        // (gtk allows this only if the tab childs are visible, thats why it's here)
458        m_TreeViewNotebook.set_current_page(1);
459  }  }
460    
461  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 610  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 1008  void MainWindow::on_action_help_about() Line 1058  void MainWindow::on_action_help_about()
1058  }  }
1059    
1060  PropDialog::PropDialog()  PropDialog::PropDialog()
1061      : eName(_("Name")),      : eFileFormat(_("File Format")),
1062          eName(_("Name")),
1063        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1064        eComments(_("Comments")),        eComments(_("Comments")),
1065        eProduct(_("Product")),        eProduct(_("Product")),
# Line 1025  PropDialog::PropDialog() Line 1076  PropDialog::PropDialog()
1076        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1077        eSubject(_("Subject")),        eSubject(_("Subject")),
1078        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1079        table(2, 1)        table(2, 1),
1080          m_file(NULL)
1081  {  {
1082      set_title(_("File Properties"));      set_title(_("File Properties"));
1083      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1047  PropDialog::PropDialog() Line 1099  PropDialog::PropDialog()
1099      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1100      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1101    
1102        table.add(eFileFormat);
1103      table.add(eName);      table.add(eName);
1104      table.add(eCreationDate);      table.add(eCreationDate);
1105      table.add(eComments);      table.add(eComments);
# Line 1077  PropDialog::PropDialog() Line 1130  PropDialog::PropDialog()
1130      quitButton.grab_focus();      quitButton.grab_focus();
1131      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1132          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1133        eFileFormat.signal_value_changed().connect(
1134            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1135    
1136      quitButton.show();      quitButton.show();
1137      vbox.show();      vbox.show();
1138      show_all_children();      show_all_children();
1139  }  }
1140    
1141    void PropDialog::set_file(gig::File* file)
1142    {
1143        m_file = file;
1144    
1145        // update file format version combo box
1146        const std::string sGiga = "Gigasampler/GigaStudio v";
1147        const int major = file->pVersion->major;
1148        std::vector<std::string> txts;
1149        std::vector<int> values;
1150        txts.push_back(sGiga + "2"); values.push_back(2);
1151        txts.push_back(sGiga + "3/v4"); values.push_back(3);
1152        if (major != 2 && major != 3) {
1153            txts.push_back(sGiga + ToString(major)); values.push_back(major);
1154        }
1155        std::vector<const char*> texts;
1156        for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1157        texts.push_back(NULL); values.push_back(0);
1158        eFileFormat.set_choices(&texts[0], &values[0]);
1159        eFileFormat.set_value(major);
1160    }
1161    
1162    void PropDialog::onFileFormatChanged() {
1163        const int major = eFileFormat.get_value();
1164        if (m_file) m_file->pVersion->major = major;
1165    }
1166    
1167  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1168  {  {
1169      update(info);      update(info);
# Line 1224  void MainWindow::load_gig(gig::File* gig Line 1305  void MainWindow::load_gig(gig::File* gig
1305      file_has_name = filename;      file_has_name = filename;
1306      file_is_changed = false;      file_is_changed = false;
1307    
1308        propDialog.set_file(gig);
1309      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1310    
1311      instrument_name_connection.block();      instrument_name_connection.block();
# Line 1998  void MainWindow::on_sample_label_drop_dr Line 2080  void MainWindow::on_sample_label_drop_dr
2080          bool channels_changed = false;          bool channels_changed = false;
2081          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2082              // remove the samplechannel dimension              // remove the samplechannel dimension
2083    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2084              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2085              channels_changed = true;              channels_changed = true;
2086              region_changed();              region_changed();
2087    */
2088          }          }
2089          dimreg_edit.set_sample(          dimreg_edit.set_sample(
2090              sample,              sample,
# Line 2100  void MainWindow::instrument_name_changed Line 2184  void MainWindow::instrument_name_changed
2184      }      }
2185  }  }
2186    
2187    void MainWindow::on_action_combine_instruments() {
2188        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2189        d->show_all();
2190        d->resize(500, 400);
2191        d->run();
2192        if (d->fileWasChanged()) {
2193            // update GUI with new instrument just created
2194            add_instrument(d->newCombinedInstrument());
2195        }
2196        delete d;
2197    }
2198    
2199    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2200        struct _Source {
2201            std::vector<RIFF::File*> riffs;
2202            std::vector<gig::File*> gigs;
2203            
2204            ~_Source() {
2205                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2206                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2207                riffs.clear();
2208                gigs.clear();
2209            }
2210        } sources;
2211    
2212        if (filenames.empty())
2213            throw RIFF::Exception(_("No files selected, so nothing done."));
2214    
2215        // first open all input files (to avoid output file corruption)
2216        int i;
2217        try {
2218            for (i = 0; i < filenames.size(); ++i) {
2219                const std::string& filename = filenames[i];
2220                printf("opening file=%s\n", filename.c_str());
2221    
2222                RIFF::File* riff = new RIFF::File(filename);
2223                sources.riffs.push_back(riff);
2224    
2225                gig::File* gig = new gig::File(riff);
2226                sources.gigs.push_back(gig);
2227            }
2228        } catch (RIFF::Exception e) {
2229            throw RIFF::Exception(
2230                _("Error occurred while opening '") +
2231                filenames[i] +
2232                "': " +
2233                e.Message
2234            );
2235        } catch (...) {
2236            throw RIFF::Exception(
2237                _("Unknown exception occurred while opening '") +
2238                filenames[i] + "'"
2239            );
2240        }
2241    
2242        // now merge the opened .gig files to the main .gig file currently being
2243        // open in gigedit
2244        try {
2245            for (i = 0; i < filenames.size(); ++i) {
2246                const std::string& filename = filenames[i];
2247                printf("merging file=%s\n", filename.c_str());
2248                assert(i < sources.gigs.size());
2249    
2250                this->file->AddContentOf(sources.gigs[i]);
2251            }
2252        } catch (RIFF::Exception e) {
2253            throw RIFF::Exception(
2254                _("Error occurred while merging '") +
2255                filenames[i] +
2256                "': " +
2257                e.Message
2258            );
2259        } catch (...) {
2260            throw RIFF::Exception(
2261                _("Unknown exception occurred while merging '") +
2262                filenames[i] + "'"
2263            );
2264        }
2265    
2266        // Note: requires that this file already has a filename !
2267        this->file->Save();
2268    }
2269    
2270    void MainWindow::on_action_merge_files() {
2271        if (this->file->GetFileName().empty()) {
2272            Glib::ustring txt = _(
2273                "You seem to have a new .gig file open that has not been saved "
2274                "yet. You must save it somewhere before starting to merge it with "
2275                "other .gig files though, because during the merge operation the "
2276                "other files' sample data must be written on file level to the "
2277                "target .gig file."
2278            );
2279            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2280            msg.run();
2281            return;
2282        }
2283    
2284        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2285        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2286        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2287        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2288    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2289        Gtk::FileFilter filter;
2290        filter.add_pattern("*.gig");
2291    #else
2292        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2293        filter->add_pattern("*.gig");
2294    #endif
2295        dialog.set_filter(filter);
2296        if (current_gig_dir != "") {
2297            dialog.set_current_folder(current_gig_dir);
2298        }
2299        dialog.set_select_multiple(true);
2300    
2301        // show warning in the file picker dialog
2302        Gtk::HBox descriptionArea;
2303        descriptionArea.set_spacing(15);
2304        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2305        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2306    #if GTKMM_MAJOR_VERSION < 3
2307        view::WrapLabel description;
2308    #else
2309        Gtk::Label description;
2310        description.set_line_wrap();
2311    #endif
2312        description.set_markup(_(
2313            "\nSelect at least one .gig file that shall be merged to the .gig file "
2314            "currently being open in gigedit.\n\n"
2315            "<b>Please Note:</b> Merging with other files will modify your "
2316            "currently open .gig file on file level! And be aware that the current "
2317            "merge algorithm does not detect duplicate samples yet. So if you are "
2318            "merging files which are using equivalent sample data, those "
2319            "equivalent samples will currently be treated as separate samples and "
2320            "will accordingly be stored separately in the target .gig file!"
2321        ));
2322        descriptionArea.pack_start(description);
2323        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2324        descriptionArea.show_all();
2325    
2326        if (dialog.run() == Gtk::RESPONSE_OK) {
2327            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2328            std::vector<std::string> filenames = dialog.get_filenames();
2329    
2330            // merge the selected files to the currently open .gig file
2331            try {
2332                mergeFiles(filenames);
2333            } catch (RIFF::Exception e) {
2334                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2335                msg.run();
2336            }
2337    
2338            // update GUI
2339            __refreshEntireGUI();        
2340        }
2341    }
2342    
2343  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2344      this->file_is_shared = b;      this->file_is_shared = b;
2345    

Legend:
Removed from v.2541  
changed lines
  Added in v.2579

  ViewVC Help
Powered by ViewVC