/[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 2664 by schoenebeck, Sat Jul 5 19:43:14 2014 UTC revision 2715 by schoenebeck, Tue Jan 20 18:48:15 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2015 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 217  MainWindow::MainWindow() : Line 217  MainWindow::MainWindow() :
217          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
218      );      );
219    
220        toggle_action =
221            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
222        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
223        actionGroup->add(
224            toggle_action,
225            sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
226        );
227    
228    
229      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
230    
# Line 253  MainWindow::MainWindow() : Line 261  MainWindow::MainWindow() :
261          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
262      );      );
263      actionGroup->add(      actionGroup->add(
264            Gtk::Action::create("ReplaceSample",
265                                _("Replace Sample...")),
266            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
267        );
268        actionGroup->add(
269          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
270                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
271          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
# Line 304  MainWindow::MainWindow() : Line 317  MainWindow::MainWindow() :
317          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
318          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
319          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
320            "      <menuitem action='ReplaceSample' />"
321          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
322          "      <separator/>"          "      <separator/>"
323          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
# Line 336  MainWindow::MainWindow() : Line 350  MainWindow::MainWindow() :
350          "    </menu>"          "    </menu>"
351          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
352          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
353            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
354          "    </menu>"          "    </menu>"
355          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
356          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 355  MainWindow::MainWindow() : Line 370  MainWindow::MainWindow() :
370          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
371          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
372          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
373            "    <menuitem action='ReplaceSample' />"
374          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
375          "    <separator/>"          "    <separator/>"
376          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
# Line 397  MainWindow::MainWindow() : Line 413  MainWindow::MainWindow() :
413      }      }
414      {      {
415          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
416                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
417            item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
418        }
419        {
420            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
421              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
422          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
423      }      }
# Line 434  MainWindow::MainWindow() : Line 455  MainWindow::MainWindow() :
455      // Create the Tree model:      // Create the Tree model:
456      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
457      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
458      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
459      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
460          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
461      );      );
# Line 442  MainWindow::MainWindow() : Line 463  MainWindow::MainWindow() :
463      // Add the TreeView's view columns:      // Add the TreeView's view columns:
464      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);
465      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
466        
467        // establish drag&drop within the instrument tree view, allowing to reorder
468        // the sequence of instruments within the gig file
469        {
470            std::vector<Gtk::TargetEntry> drag_target_instrument;
471            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
472            m_TreeView.drag_source_set(drag_target_instrument);
473            m_TreeView.drag_dest_set(drag_target_instrument);
474            m_TreeView.signal_drag_begin().connect(
475                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
476            );
477            m_TreeView.signal_drag_data_get().connect(
478                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
479            );
480            m_TreeView.signal_drag_data_received().connect(
481                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
482            );
483        }
484    
485      // create samples treeview (including its data model)      // create samples treeview (including its data model)
486      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
# Line 489  MainWindow::MainWindow() : Line 528  MainWindow::MainWindow() :
528      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
529          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
530      );      );
531      //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?      //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
532      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
533          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
534      );      );
# Line 548  MainWindow::MainWindow() : Line 587  MainWindow::MainWindow() :
587          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
588      );      );
589    
590        dimreg_edit.signal_select_sample().connect(
591            sigc::mem_fun(*this, &MainWindow::select_sample)
592        );
593    
594      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
595          sigc::hide(          sigc::hide(
596              sigc::bind(              sigc::bind(
# Line 688  void MainWindow::on_sel_change() Line 731  void MainWindow::on_sel_change()
731      }      }
732    
733      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
734    
735        if (Settings::singleton()->syncSamplerInstrumentSelection) {
736            switch_sampler_instrument_signal.emit(get_instrument());
737        }
738  }  }
739    
740  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 708  void Loader::progress_callback(float fra Line 755  void Loader::progress_callback(float fra
755  void Loader::thread_function()  void Loader::thread_function()
756  {  {
757      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
758      printf("Start %s\n", filename);      printf("Start %s\n", filename.c_str());
759      RIFF::File* riff = new RIFF::File(filename);      try {
760      gig = new gig::File(riff);          RIFF::File* riff = new RIFF::File(filename);
761      gig::progress_t progress;          gig = new gig::File(riff);
762      progress.callback = loader_progress_callback;          gig::progress_t progress;
763      progress.custom = this;          progress.callback = loader_progress_callback;
764            progress.custom = this;
765      gig->GetInstrument(0, &progress);  
766      printf("End\n");          gig->GetInstrument(0, &progress);
767      finished_dispatcher();          printf("End\n");
768            finished_dispatcher();
769        } catch (RIFF::Exception e) {
770            error_message = e.Message;
771            error_dispatcher.emit();
772        } catch (...) {
773            error_message = _("Unknown exception occurred");
774            error_dispatcher.emit();
775        }
776  }  }
777    
778  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
779      : filename(filename), thread(0)      : filename(filename), thread(0), progress(0.f)
780  {  {
781  }  }
782    
# Line 755  Glib::Dispatcher& Loader::signal_finishe Line 810  Glib::Dispatcher& Loader::signal_finishe
810      return finished_dispatcher;      return finished_dispatcher;
811  }  }
812    
813  LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)  Glib::Dispatcher& Loader::signal_error()
814    {
815        return error_dispatcher;
816    }
817    
818    void saver_progress_callback(gig::progress_t* progress)
819    {
820        Saver* saver = static_cast<Saver*>(progress->custom);
821        saver->progress_callback(progress->factor);
822    }
823    
824    void Saver::progress_callback(float fraction)
825    {
826        {
827            Glib::Threads::Mutex::Lock lock(progressMutex);
828            progress = fraction;
829        }
830        progress_dispatcher.emit();
831    }
832    
833    void Saver::thread_function()
834    {
835        printf("thread_function self=%x\n", Glib::Threads::Thread::self());
836        printf("Start %s\n", filename.c_str());
837        try {
838            gig::progress_t progress;
839            progress.callback = saver_progress_callback;
840            progress.custom = this;
841    
842            // if no filename was provided, that means "save", if filename was provided means "save as"
843            if (filename.empty()) {
844                gig->Save(&progress);
845            } else {
846                gig->Save(filename, &progress);
847            }
848    
849            printf("End\n");
850            finished_dispatcher.emit();
851        } catch (RIFF::Exception e) {
852            error_message = e.Message;
853            error_dispatcher.emit();
854        } catch (...) {
855            error_message = _("Unknown exception occurred");
856            error_dispatcher.emit();
857        }
858    }
859    
860    Saver::Saver(gig::File* file, Glib::ustring filename)
861        : gig(file), filename(filename), thread(0), progress(0.f)
862    {
863    }
864    
865    void Saver::launch()
866    {
867    #ifdef OLD_THREADS
868        thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
869    #else
870        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
871    #endif
872        printf("launch thread=%x\n", thread);
873    }
874    
875    float Saver::get_progress()
876    {
877        float res;
878        {
879            Glib::Threads::Mutex::Lock lock(progressMutex);
880            res = progress;
881        }
882        return res;
883    }
884    
885    Glib::Dispatcher& Saver::signal_progress()
886    {
887        return progress_dispatcher;
888    }
889    
890    Glib::Dispatcher& Saver::signal_finished()
891    {
892        return finished_dispatcher;
893    }
894    
895    Glib::Dispatcher& Saver::signal_error()
896    {
897        return error_dispatcher;
898    }
899    
900    ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
901      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
902  {  {
903      get_vbox()->pack_start(progressBar);      get_vbox()->pack_start(progressBar);
904      show_all_children();      show_all_children();
905        resize(600,50);
906  }  }
907    
908  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
# Line 828  bool MainWindow::close_confirmation_dial Line 971  bool MainWindow::close_confirmation_dial
971      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
972      int response = dialog.run();      int response = dialog.run();
973      dialog.hide();      dialog.hide();
974      if (response == Gtk::RESPONSE_YES) return file_save();  
975      return response != Gtk::RESPONSE_CANCEL;      // user decided to exit app without saving
976        if (response == Gtk::RESPONSE_NO) return true;
977    
978        // user cancelled dialog, thus don't close app
979        if (response == Gtk::RESPONSE_CANCEL) return false;
980    
981        // TODO: the following return valid is disabled and hard coded instead for
982        // now, due to the fact that saving with progress bar is now implemented
983        // asynchronously, as a result the app does not close automatically anymore
984        // after saving the file has completed
985        //
986        //   if (response == Gtk::RESPONSE_YES) return file_save();
987        //   return response != Gtk::RESPONSE_CANCEL;
988        //
989        if (response == Gtk::RESPONSE_YES) file_save();
990        return false; // always prevent closing the app for now (see comment above)
991  }  }
992    
993  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
# Line 880  void MainWindow::on_action_file_open() Line 1038  void MainWindow::on_action_file_open()
1038  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
1039  {  {
1040      __clear();      __clear();
1041      load_dialog = new LoadDialog(_("Loading..."), *this);  
1042      load_dialog->show_all();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1043      loader = new Loader(strdup(name));          _("Loading") +  Glib::ustring(" '") +
1044            Glib::filename_display_basename(name) + "' ...",
1045            *this
1046        );
1047        progress_dialog->show_all();
1048        loader = new Loader(name); //FIXME: memory leak!
1049      loader->signal_progress().connect(      loader->signal_progress().connect(
1050          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
1051      loader->signal_finished().connect(      loader->signal_finished().connect(
1052          sigc::mem_fun(*this, &MainWindow::on_loader_finished));          sigc::mem_fun(*this, &MainWindow::on_loader_finished));
1053        loader->signal_error().connect(
1054            sigc::mem_fun(*this, &MainWindow::on_loader_error));
1055      loader->launch();      loader->launch();
1056  }  }
1057    
# Line 928  void MainWindow::load_instrument(gig::In Line 1093  void MainWindow::load_instrument(gig::In
1093    
1094  void MainWindow::on_loader_progress()  void MainWindow::on_loader_progress()
1095  {  {
1096      load_dialog->set_fraction(loader->get_progress());      progress_dialog->set_fraction(loader->get_progress());
1097  }  }
1098    
1099  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1100  {  {
1101      printf("Loader finished!\n");      printf("Loader finished!\n");
1102      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
1103      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename.c_str());
1104      load_dialog->hide();      progress_dialog->hide();
1105    }
1106    
1107    void MainWindow::on_loader_error()
1108    {
1109        Glib::ustring txt = _("Could not load file: ") + loader->error_message;
1110        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1111        msg.run();
1112        progress_dialog->hide();
1113  }  }
1114    
1115  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
# Line 975  bool MainWindow::file_save() Line 1148  bool MainWindow::file_save()
1148    
1149      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
1150      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
1151      try {  
1152          file->Save();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
1153          if (file_is_changed) {          _("Saving") +  Glib::ustring(" '") +
1154              set_title(get_title().substr(1));          Glib::filename_display_basename(this->filename) + "' ...",
1155              file_is_changed = false;          *this
1156          }      );
1157      } catch (RIFF::Exception e) {      progress_dialog->show_all();
1158          file_structure_changed_signal.emit(this->file);      saver = new Saver(this->file); //FIXME: memory leak!
1159          Glib::ustring txt = _("Could not save file: ") + e.Message;      saver->signal_progress().connect(
1160          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1161          msg.run();      saver->signal_finished().connect(
1162          return false;          sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1163      }      saver->signal_error().connect(
1164      std::cout << "Saving file done\n" << std::flush;          sigc::mem_fun(*this, &MainWindow::on_saver_error));
1165        saver->launch();
1166    
1167        return true;
1168    }
1169    
1170    void MainWindow::on_saver_progress()
1171    {
1172        progress_dialog->set_fraction(saver->get_progress());
1173    }
1174    
1175    void MainWindow::on_saver_error()
1176    {
1177        file_structure_changed_signal.emit(this->file);
1178        Glib::ustring txt = _("Could not save file: ") + saver->error_message;
1179        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1180        msg.run();
1181    }
1182    
1183    void MainWindow::on_saver_finished()
1184    {
1185        this->file = saver->gig;
1186        this->filename = saver->filename;
1187        current_gig_dir = Glib::path_get_dirname(filename);
1188        set_title(Glib::filename_display_basename(filename));
1189        file_has_name = true;
1190        file_is_changed = false;
1191        std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
1192      __import_queued_samples();      __import_queued_samples();
1193        std::cout << "Importing queued samples done.\n" << std::flush;
1194    
1195      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1196      return true;  
1197        __refreshEntireGUI();
1198        progress_dialog->hide();
1199  }  }
1200    
1201  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
# Line 1056  bool MainWindow::file_save_as() Line 1260  bool MainWindow::file_save_as()
1260      descriptionArea.show_all();      descriptionArea.show_all();
1261    
1262      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1263          file_structure_to_be_changed_signal.emit(this->file);          std::string filename = dialog.get_filename();
1264          try {          if (!Glib::str_has_suffix(filename, ".gig")) {
1265              std::string filename = dialog.get_filename();              filename += ".gig";
             if (!Glib::str_has_suffix(filename, ".gig")) {  
                 filename += ".gig";  
             }  
             printf("filename=%s\n", filename.c_str());  
             file->Save(filename);  
             this->filename = filename;  
             current_gig_dir = Glib::path_get_dirname(filename);  
             set_title(Glib::filename_display_basename(filename));  
             file_has_name = true;  
             file_is_changed = false;  
         } catch (RIFF::Exception e) {  
             file_structure_changed_signal.emit(this->file);  
             Glib::ustring txt = _("Could not save file: ") + e.Message;  
             Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);  
             msg.run();  
             return false;  
1266          }          }
1267          __import_queued_samples();          printf("filename=%s\n", filename.c_str());
1268          file_structure_changed_signal.emit(this->file);  
1269            progress_dialog = new ProgressDialog( //FIXME: memory leak!
1270                _("Saving") +  Glib::ustring(" '") +
1271                Glib::filename_display_basename(filename) + "' ...",
1272                *this
1273            );
1274            progress_dialog->show_all();
1275    
1276            saver = new Saver(file, filename); //FIXME: memory leak!
1277            saver->signal_progress().connect(
1278                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
1279            saver->signal_finished().connect(
1280                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
1281            saver->signal_error().connect(
1282                sigc::mem_fun(*this, &MainWindow::on_saver_error));
1283            saver->launch();
1284    
1285          return true;          return true;
1286      }      }
1287      return false;      return false;
# Line 1188  void MainWindow::on_action_warn_user_on_ Line 1392  void MainWindow::on_action_warn_user_on_
1392          !Settings::singleton()->warnUserOnExtensions;          !Settings::singleton()->warnUserOnExtensions;
1393  }  }
1394    
1395    void MainWindow::on_action_sync_sampler_instrument_selection() {
1396        Settings::singleton()->syncSamplerInstrumentSelection =
1397            !Settings::singleton()->syncSamplerInstrumentSelection;
1398    }
1399    
1400  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1401  {  {
1402      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1197  void MainWindow::on_action_help_about() Line 1406  void MainWindow::on_action_help_about()
1406      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1407  #endif  #endif
1408      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1409      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");
1410      const std::string sComment =      const std::string sComment =
1411          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1412          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1709  void MainWindow::on_instrument_selection Line 1918  void MainWindow::on_instrument_selection
1918      }      }
1919  }  }
1920    
1921    void MainWindow::select_instrument(gig::Instrument* instrument) {
1922        if (!instrument) return;
1923    
1924        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1925        for (int i = 0; i < model->children().size(); ++i) {
1926            Gtk::TreeModel::Row row = model->children()[i];
1927            if (row[m_Columns.m_col_instr] == instrument) {
1928                // select and show the respective instrument in the list view
1929                show_intruments_tab();
1930                m_TreeView.get_selection()->select(model->children()[i]);
1931                Gtk::TreePath path(
1932                    m_TreeView.get_selection()->get_selected()
1933                );
1934                m_TreeView.scroll_to_row(path);
1935                on_sel_change(); // the regular instrument selection change callback
1936            }
1937        }
1938    }
1939    
1940    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
1941    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
1942        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
1943        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
1944    
1945        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1946        for (int i = 0; i < model->children().size(); ++i) {
1947            Gtk::TreeModel::Row row = model->children()[i];
1948            if (row[m_Columns.m_col_instr] == pInstrument) {
1949                // select and show the respective instrument in the list view
1950                show_intruments_tab();
1951                m_TreeView.get_selection()->select(model->children()[i]);
1952                Gtk::TreePath path(
1953                    m_TreeView.get_selection()->get_selected()
1954                );
1955                m_TreeView.scroll_to_row(path);
1956                on_sel_change(); // the regular instrument selection change callback
1957    
1958                // select respective region in the region selector
1959                m_RegionChooser.set_region(pRegion);
1960    
1961                // select and show the respective dimension region in the editor
1962                //update_dimregs();
1963                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
1964                //dimreg_edit.set_dim_region(dimRgn);
1965    
1966                return true;
1967            }
1968        }
1969    
1970        return false;
1971    }
1972    
1973    void MainWindow::select_sample(gig::Sample* sample) {
1974        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
1975        for (int g = 0; g < model->children().size(); ++g) {
1976            Gtk::TreeModel::Row rowGroup = model->children()[g];
1977            for (int s = 0; s < rowGroup.children().size(); ++s) {
1978                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
1979                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
1980                    show_samples_tab();
1981                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
1982                    Gtk::TreePath path(
1983                        m_TreeViewSamples.get_selection()->get_selected()
1984                    );
1985                    m_TreeViewSamples.scroll_to_row(path);
1986                    return;
1987                }
1988            }
1989        }
1990    }
1991    
1992  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
1993      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1994          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
# Line 2061  void MainWindow::on_action_add_group() { Line 2341  void MainWindow::on_action_add_group() {
2341      file_changed();      file_changed();
2342  }  }
2343    
2344    void MainWindow::on_action_replace_sample() {
2345        add_or_replace_sample(true);
2346    }
2347    
2348  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2349        add_or_replace_sample(false);
2350    }
2351    
2352    void MainWindow::add_or_replace_sample(bool replace) {
2353      if (!file) return;      if (!file) return;
2354      // get selected group  
2355        // get selected group (and probably selected sample)
2356      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2357      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
2358      if (!it) return;      if (!it) return;
2359      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2360        gig::Sample* sample = NULL;
2361      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2362      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2363          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2364          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2365          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2366          if (!it) return;          if (!it) return;
2367          row = *it;          if (!replace) row = *it;
2368          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2369          if (!group) return;          if (!group) return;
2370      }      }
2371        if (replace && !sample) return;
2372    
2373      // show 'browse for file' dialog      // show 'browse for file' dialog
2374      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2375      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2376      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2377      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2378    
2379      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2380  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 2153  void MainWindow::on_action_add_sample() Line 2445  void MainWindow::on_action_add_sample()
2445                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2446                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2447                  }                  }
2448                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2449                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2450                  // file name without path                  // file name without path
2451                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2452                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2205  void MainWindow::on_action_add_sample() Line 2497  void MainWindow::on_action_add_sample()
2497                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2498                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2499                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2500                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2501                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2502                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2503                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 2213  void MainWindow::on_action_add_sample() Line 2505  void MainWindow::on_action_add_sample()
2505                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2506                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2507                  // add sample to the tree view                  // add sample to the tree view
2508                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2509                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2510                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2511                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2512                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2513                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2514                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2515                            gig_to_utf8(sample->pInfo->Name);
2516                        rowSample[m_SamplesModel.m_col_sample] = sample;
2517                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2518                    }
2519                  // close sound file                  // close sound file
2520                  sf_close(hFile);                  sf_close(hFile);
2521                  file_changed();                  file_changed();
# Line 2230  void MainWindow::on_action_add_sample() Line 2526  void MainWindow::on_action_add_sample()
2526          }          }
2527          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
2528          if (!error_files.empty()) {          if (!error_files.empty()) {
2529              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2530                    (replace
2531                        ? _("Failed to replace sample with:\n")
2532                        : _("Could not add the following sample(s):\n"))
2533                    + error_files;
2534              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2535              msg.run();              msg.run();
2536          }          }
# Line 2440  void MainWindow::on_scripts_treeview_dra Line 2740  void MainWindow::on_scripts_treeview_dra
2740                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
2741  }  }
2742    
2743    // see comment on on_sample_treeview_drag_begin()
2744    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2745    {
2746        first_call_to_drag_data_get = true;
2747    }
2748    
2749    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2750                                                           Gtk::SelectionData& selection_data, guint, guint)
2751    {
2752        if (!first_call_to_drag_data_get) return;
2753        first_call_to_drag_data_get = false;
2754    
2755        // get selected source instrument
2756        gig::Instrument* src = NULL;
2757        {
2758            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2759            Gtk::TreeModel::iterator it = sel->get_selected();
2760            if (it) {
2761                Gtk::TreeModel::Row row = *it;
2762                src = row[m_Columns.m_col_instr];
2763            }
2764        }
2765        if (!src) return;
2766    
2767        // pass the source gig::Instrument as pointer
2768        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
2769                           sizeof(src)/*length of data in bytes*/);
2770    }
2771    
2772    void MainWindow::on_instruments_treeview_drop_drag_data_received(
2773        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
2774        const Gtk::SelectionData& selection_data, guint, guint time)
2775    {
2776        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
2777        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
2778            return;
2779    
2780        gig::Instrument* dst = NULL;
2781        {
2782            Gtk::TreeModel::Path path;
2783            const bool found = m_TreeView.get_path_at_pos(x, y, path);
2784            if (!found) return;
2785    
2786            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
2787            if (!iter) return;
2788            Gtk::TreeModel::Row row = *iter;
2789            dst = row[m_Columns.m_col_instr];
2790        }
2791        if (!dst) return;
2792    
2793        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
2794        src->MoveTo(dst);
2795        __refreshEntireGUI();
2796        select_instrument(src);
2797    }
2798    
2799  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2800  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
2801  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 2662  void MainWindow::on_action_view_referenc Line 3018  void MainWindow::on_action_view_referenc
3018    
3019      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
3020      d->setSample(sample);      d->setSample(sample);
3021        d->dimension_region_selected.connect(
3022            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3023        );
3024      d->show_all();      d->show_all();
3025      d->resize(500, 400);      d->resize(500, 400);
3026      d->run();      d->run();
# Line 2735  void MainWindow::mergeFiles(const std::v Line 3094  void MainWindow::mergeFiles(const std::v
3094          );          );
3095      }      }
3096    
3097      // Note: requires that this file already has a filename !      // Finally save gig file persistently to disk ...
3098      this->file->Save();      //NOTE: requires that this gig file already has a filename !
3099        {
3100            std::cout << "Saving file\n" << std::flush;
3101            file_structure_to_be_changed_signal.emit(this->file);
3102    
3103            progress_dialog = new ProgressDialog( //FIXME: memory leak!
3104                _("Saving") +  Glib::ustring(" '") +
3105                Glib::filename_display_basename(this->filename) + "' ...",
3106                *this
3107            );
3108            progress_dialog->show_all();
3109            saver = new Saver(this->file); //FIXME: memory leak!
3110            saver->signal_progress().connect(
3111                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
3112            saver->signal_finished().connect(
3113                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
3114            saver->signal_error().connect(
3115                sigc::mem_fun(*this, &MainWindow::on_saver_error));
3116            saver->launch();
3117        }
3118  }  }
3119    
3120  void MainWindow::on_action_merge_files() {  void MainWindow::on_action_merge_files() {
# Line 2826  void MainWindow::set_file_is_shared(bool Line 3204  void MainWindow::set_file_is_shared(bool
3204              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
3205          );          );
3206      }      }
3207    
3208        {
3209            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
3210                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
3211            if (item) item->set_sensitive(b);
3212        }
3213  }  }
3214    
3215  void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {  void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
# Line 2854  void MainWindow::on_samples_to_be_remove Line 3238  void MainWindow::on_samples_to_be_remove
3238      // just in case a new sample is added later with exactly the same memory      // just in case a new sample is added later with exactly the same memory
3239      // address, which would lead to incorrect refcount if not deleted here      // address, which would lead to incorrect refcount if not deleted here
3240      for (std::list<gig::Sample*>::const_iterator it = samples.begin();      for (std::list<gig::Sample*>::const_iterator it = samples.begin();
3241           it != samples.end(); it != samples.end())           it != samples.end(); ++it)
3242      {      {
3243          sample_ref_count.erase(*it);          sample_ref_count.erase(*it);
3244      }      }
# Line 2927  sigc::signal<void, int/*key*/, int/*velo Line 3311  sigc::signal<void, int/*key*/, int/*velo
3311  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
3312      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
3313  }  }
3314    
3315    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
3316        return switch_sampler_instrument_signal;
3317    }

Legend:
Removed from v.2664  
changed lines
  Added in v.2715

  ViewVC Help
Powered by ViewVC