/[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 2689 by schoenebeck, Sun Jan 4 17:19:19 2015 UTC revision 2715 by schoenebeck, Tue Jan 20 18:48:15 2015 UTC
# Line 261  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 312  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 364  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 448  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 456  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 503  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 562  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 943  bool MainWindow::close_confirmation_dial Line 972  bool MainWindow::close_confirmation_dial
972      int response = dialog.run();      int response = dialog.run();
973      dialog.hide();      dialog.hide();
974    
975        // 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      // 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      // 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      // asynchronously, as a result the app does not close automatically anymore
# Line 1159  void MainWindow::on_saver_finished() Line 1194  void MainWindow::on_saver_finished()
1194    
1195      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1196    
1197      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1198      progress_dialog->hide();      progress_dialog->hide();
1199  }  }
1200    
# Line 1883  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 2235  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 2327  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 2379  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 2387  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 2404  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 2614  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 2836  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();

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

  ViewVC Help
Powered by ViewVC