--- gigedit/trunk/src/gigedit/mainwindow.cpp 2014/05/24 06:44:39 2579
+++ gigedit/trunk/src/gigedit/mainwindow.cpp 2014/12/29 16:30:21 2683
@@ -45,11 +45,15 @@
#include "mainwindow.h"
#include "Settings.h"
#include "CombineInstrumentsDialog.h"
+#include "scripteditor.h"
+#include "scriptslots.h"
+#include "ReferencesView.h"
#include "../../gfx/status_attached.xpm"
#include "../../gfx/status_detached.xpm"
MainWindow::MainWindow() :
+ m_DimRegionChooser(*this),
dimreg_label(_("Changes apply to:")),
dimreg_all_regions(_("all regions")),
dimreg_all_dimregs(_("all dimension splits")),
@@ -78,6 +82,9 @@
m_ScrolledWindowSamples.add(m_TreeViewSamples);
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+ m_ScrolledWindowScripts.add(m_TreeViewScripts);
+ m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+
m_TreeViewNotebook.set_size_request(300);
@@ -98,7 +105,7 @@
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
-
+ m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
actionGroup = Gtk::ActionGroup::create();
@@ -130,14 +137,29 @@
sigc::mem_fun(
*this, &MainWindow::show_instr_props));
actionGroup->add(Gtk::Action::create("MidiRules",
- _("_Midi Rules")),
+ _("_Midi Rules...")),
sigc::mem_fun(
*this, &MainWindow::show_midi_rules));
+ actionGroup->add(Gtk::Action::create("ScriptSlots",
+ _("_Script Slots...")),
+ sigc::mem_fun(
+ *this, &MainWindow::show_script_slots));
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
sigc::mem_fun(
*this, &MainWindow::on_action_quit));
- actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
-
+ actionGroup->add(
+ Gtk::Action::create("MenuSample", _("_Sample")),
+ sigc::mem_fun(*this, &MainWindow::show_samples_tab)
+ );
+ actionGroup->add(
+ Gtk::Action::create("MenuInstrument", _("_Instrument")),
+ sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
+ );
+ actionGroup->add(
+ Gtk::Action::create("MenuScript", _("S_cript")),
+ sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
+ );
+ actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
@@ -227,10 +249,32 @@
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
);
actionGroup->add(
+ Gtk::Action::create("ShowSampleRefs", _("Show References...")),
+ sigc::mem_fun(*this, &MainWindow::on_action_view_references)
+ );
+ actionGroup->add(
Gtk::Action::create("ReplaceAllSamplesInAllGroups",
_("Replace All Samples in All Groups...")),
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
);
+
+ // script right-click popup actions
+ actionGroup->add(
+ Gtk::Action::create("AddScriptGroup", _("Add _Group")),
+ sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
+ );
+ actionGroup->add(
+ Gtk::Action::create("AddScript", _("Add _Script")),
+ sigc::mem_fun(*this, &MainWindow::on_action_add_script)
+ );
+ actionGroup->add(
+ Gtk::Action::create("EditScript", _("_Edit Script...")),
+ sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
+ );
+ actionGroup->add(
+ Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
+ sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
+ );
uiManager = Gtk::UIManager::create();
uiManager->insert_action_group(actionGroup);
@@ -255,7 +299,33 @@
" "
" "
" "
+ "
"
" "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
" "
" "
" "
@@ -274,6 +344,7 @@
" "
" "
" "
+ " "
" "
" "
" "
@@ -283,10 +354,18 @@
" "
" "
" "
+ " "
" "
" "
" "
" "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
+ " "
"";
uiManager->add_ui_from_string(ui_info);
@@ -329,7 +408,7 @@
instrument_menu = static_cast(
- uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
+ uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
@@ -369,8 +448,25 @@
m_TreeViewSamples.set_model(m_refSamplesTreeModel);
m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
// m_TreeViewSamples.set_reorderable();
- m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
- m_TreeViewSamples.set_headers_visible(false);
+ m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
+ m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
+ {
+ Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
+ Gtk::CellRendererText* cellrenderer =
+ dynamic_cast(column->get_first_cell());
+ column->add_attribute(
+ cellrenderer->property_foreground(), m_SamplesModel.m_color
+ );
+ }
+ {
+ Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
+ Gtk::CellRendererText* cellrenderer =
+ dynamic_cast(column->get_first_cell());
+ column->add_attribute(
+ cellrenderer->property_foreground(), m_SamplesModel.m_color
+ );
+ }
+ m_TreeViewSamples.set_headers_visible(true);
m_TreeViewSamples.signal_button_press_event().connect_notify(
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
);
@@ -378,6 +474,40 @@
sigc::mem_fun(*this, &MainWindow::sample_name_changed)
);
+ // create scripts treeview (including its data model)
+ m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
+ m_TreeViewScripts.set_model(m_refScriptsTreeModel);
+ m_TreeViewScripts.set_tooltip_text(_(
+ "Use CTRL + double click for editing a script."
+ "\n\n"
+ "Note: instrument scripts are a LinuxSampler extension of the gig "
+ "format. This feature will not work with the GigaStudio software!"
+ ));
+ // m_TreeViewScripts.set_reorderable();
+ m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
+ m_TreeViewScripts.set_headers_visible(false);
+ m_TreeViewScripts.signal_button_press_event().connect_notify(
+ sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
+ );
+ //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?
+ m_TreeViewScripts.signal_row_activated().connect(
+ sigc::mem_fun(*this, &MainWindow::script_double_clicked)
+ );
+ m_refScriptsTreeModel->signal_row_changed().connect(
+ sigc::mem_fun(*this, &MainWindow::script_name_changed)
+ );
+
+ // establish drag&drop between scripts tree view and ScriptSlots window
+ std::vector drag_target_gig_script;
+ drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
+ m_TreeViewScripts.drag_source_set(drag_target_gig_script);
+ m_TreeViewScripts.signal_drag_begin().connect(
+ sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
+ );
+ m_TreeViewScripts.signal_drag_data_get().connect(
+ sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
+ );
+
// establish drag&drop between samples tree view and dimension region 'Sample' text entry
std::vector drag_target_gig_sample;
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
@@ -411,6 +541,12 @@
dimreg_changed_signal.make_slot());
dimreg_edit.signal_sample_ref_changed().connect(
sample_ref_changed_signal.make_slot());
+ sample_ref_changed_signal.connect(
+ sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
+ );
+ samples_to_be_removed_signal.connect(
+ sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
+ );
m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
sigc::hide(
@@ -536,7 +672,7 @@
void MainWindow::dimreg_changed()
{
update_dimregs();
- dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());
+ dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
}
void MainWindow::on_sel_change()
@@ -572,20 +708,28 @@
void Loader::thread_function()
{
printf("thread_function self=%x\n", Glib::Threads::Thread::self());
- printf("Start %s\n", filename);
- RIFF::File* riff = new RIFF::File(filename);
- gig = new gig::File(riff);
- gig::progress_t progress;
- progress.callback = loader_progress_callback;
- progress.custom = this;
-
- gig->GetInstrument(0, &progress);
- printf("End\n");
- finished_dispatcher();
+ printf("Start %s\n", filename.c_str());
+ try {
+ RIFF::File* riff = new RIFF::File(filename);
+ gig = new gig::File(riff);
+ gig::progress_t progress;
+ progress.callback = loader_progress_callback;
+ progress.custom = this;
+
+ gig->GetInstrument(0, &progress);
+ printf("End\n");
+ finished_dispatcher();
+ } catch (RIFF::Exception e) {
+ error_message = e.Message;
+ error_dispatcher.emit();
+ } catch (...) {
+ error_message = _("Unknown exception occurred");
+ error_dispatcher.emit();
+ }
}
Loader::Loader(const char* filename)
- : filename(filename), thread(0)
+ : filename(filename), thread(0), progress(0.f)
{
}
@@ -619,11 +763,99 @@
return finished_dispatcher;
}
-LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)
+Glib::Dispatcher& Loader::signal_error()
+{
+ return error_dispatcher;
+}
+
+void saver_progress_callback(gig::progress_t* progress)
+{
+ Saver* saver = static_cast(progress->custom);
+ saver->progress_callback(progress->factor);
+}
+
+void Saver::progress_callback(float fraction)
+{
+ {
+ Glib::Threads::Mutex::Lock lock(progressMutex);
+ progress = fraction;
+ }
+ progress_dispatcher.emit();
+}
+
+void Saver::thread_function()
+{
+ printf("thread_function self=%x\n", Glib::Threads::Thread::self());
+ printf("Start %s\n", filename.c_str());
+ try {
+ gig::progress_t progress;
+ progress.callback = saver_progress_callback;
+ progress.custom = this;
+
+ // if no filename was provided, that means "save", if filename was provided means "save as"
+ if (filename.empty()) {
+ gig->Save(&progress);
+ } else {
+ gig->Save(filename, &progress);
+ }
+
+ printf("End\n");
+ finished_dispatcher.emit();
+ } catch (RIFF::Exception e) {
+ error_message = e.Message;
+ error_dispatcher.emit();
+ } catch (...) {
+ error_message = _("Unknown exception occurred");
+ error_dispatcher.emit();
+ }
+}
+
+Saver::Saver(gig::File* file, Glib::ustring filename)
+ : gig(file), filename(filename), thread(0), progress(0.f)
+{
+}
+
+void Saver::launch()
+{
+#ifdef OLD_THREADS
+ thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
+#else
+ thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
+#endif
+ printf("launch thread=%x\n", thread);
+}
+
+float Saver::get_progress()
+{
+ float res;
+ {
+ Glib::Threads::Mutex::Lock lock(progressMutex);
+ res = progress;
+ }
+ return res;
+}
+
+Glib::Dispatcher& Saver::signal_progress()
+{
+ return progress_dispatcher;
+}
+
+Glib::Dispatcher& Saver::signal_finished()
+{
+ return finished_dispatcher;
+}
+
+Glib::Dispatcher& Saver::signal_error()
+{
+ return error_dispatcher;
+}
+
+ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
: Gtk::Dialog(title, parent, true)
{
get_vbox()->pack_start(progressBar);
show_all_children();
+ resize(600,50);
}
// Clear all GUI elements / controls. This method is typically called
@@ -634,6 +866,7 @@
// clear the samples and instruments tree views
m_refTreeModel->clear();
m_refSamplesTreeModel->clear();
+ m_refScriptsTreeModel->clear();
// remove all entries from "Instrument" menu
while (!instrument_menu->get_children().empty()) {
remove_instrument_from_menu(0);
@@ -648,6 +881,7 @@
// clear the samples and instruments tree views
m_refTreeModel->clear();
m_refSamplesTreeModel->clear();
+ m_refScriptsTreeModel->clear();
// remove all entries from "Instrument" menu
while (!instrument_menu->get_children().empty()) {
remove_instrument_from_menu(0);
@@ -690,8 +924,17 @@
dialog.set_default_response(Gtk::RESPONSE_YES);
int response = dialog.run();
dialog.hide();
- if (response == Gtk::RESPONSE_YES) return file_save();
- return response != Gtk::RESPONSE_CANCEL;
+
+ // TODO: the following return valid is disabled and hard coded instead for
+ // now, due to the fact that saving with progress bar is now implemented
+ // asynchronously, as a result the app does not close automatically anymore
+ // after saving the file has completed
+ //
+ // if (response == Gtk::RESPONSE_YES) return file_save();
+ // return response != Gtk::RESPONSE_CANCEL;
+ //
+ if (response == Gtk::RESPONSE_YES) file_save();
+ return false; // always prevent closing the app for now (see comment above)
}
bool MainWindow::leaving_shared_mode_dialog() {
@@ -742,13 +985,20 @@
void MainWindow::load_file(const char* name)
{
__clear();
- load_dialog = new LoadDialog(_("Loading..."), *this);
- load_dialog->show_all();
- loader = new Loader(strdup(name));
+
+ progress_dialog = new ProgressDialog( //FIXME: memory leak!
+ _("Loading") + Glib::ustring(" '") +
+ Glib::filename_display_basename(name) + "' ...",
+ *this
+ );
+ progress_dialog->show_all();
+ loader = new Loader(name); //FIXME: memory leak!
loader->signal_progress().connect(
sigc::mem_fun(*this, &MainWindow::on_loader_progress));
loader->signal_finished().connect(
sigc::mem_fun(*this, &MainWindow::on_loader_finished));
+ loader->signal_error().connect(
+ sigc::mem_fun(*this, &MainWindow::on_loader_error));
loader->launch();
}
@@ -764,20 +1014,49 @@
// load the instrument
gig::File* pFile = (gig::File*) instr->GetParent();
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
- //TODO: automatically select the given instrument
+ // automatically select the given instrument
+ int i = 0;
+ for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
+ instrument = pFile->GetNextInstrument(), ++i)
+ {
+ if (instrument == instr) {
+ // select item in "instruments" tree view
+ m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
+ // make sure the selected item in the "instruments" tree view is
+ // visible (scroll to it)
+ m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
+ // select item in instrument menu
+ {
+ const std::vector children =
+ instrument_menu->get_children();
+ static_cast(children[i])->set_active();
+ }
+ // update region chooser and dimension region chooser
+ m_RegionChooser.set_instrument(instr);
+ break;
+ }
+ }
}
void MainWindow::on_loader_progress()
{
- load_dialog->set_fraction(loader->get_progress());
+ progress_dialog->set_fraction(loader->get_progress());
}
void MainWindow::on_loader_finished()
{
printf("Loader finished!\n");
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
- load_gig(loader->gig, loader->filename);
- load_dialog->hide();
+ load_gig(loader->gig, loader->filename.c_str());
+ progress_dialog->hide();
+}
+
+void MainWindow::on_loader_error()
+{
+ Glib::ustring txt = _("Could not load file: ") + loader->error_message;
+ Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
+ msg.run();
+ progress_dialog->hide();
}
void MainWindow::on_action_file_save()
@@ -816,23 +1095,54 @@
std::cout << "Saving file\n" << std::flush;
file_structure_to_be_changed_signal.emit(this->file);
- try {
- file->Save();
- if (file_is_changed) {
- set_title(get_title().substr(1));
- 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;
- }
- std::cout << "Saving file done\n" << std::flush;
+
+ progress_dialog = new ProgressDialog( //FIXME: memory leak!
+ _("Saving") + Glib::ustring(" '") +
+ Glib::filename_display_basename(this->filename) + "' ...",
+ *this
+ );
+ progress_dialog->show_all();
+ saver = new Saver(this->file); //FIXME: memory leak!
+ saver->signal_progress().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_progress));
+ saver->signal_finished().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_finished));
+ saver->signal_error().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_error));
+ saver->launch();
+
+ return true;
+}
+
+void MainWindow::on_saver_progress()
+{
+ progress_dialog->set_fraction(saver->get_progress());
+}
+
+void MainWindow::on_saver_error()
+{
+ file_structure_changed_signal.emit(this->file);
+ Glib::ustring txt = _("Could not save file: ") + saver->error_message;
+ Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
+ msg.run();
+}
+
+void MainWindow::on_saver_finished()
+{
+ this->file = saver->gig;
+ this->filename = saver->filename;
+ current_gig_dir = Glib::path_get_dirname(filename);
+ set_title(Glib::filename_display_basename(filename));
+ file_has_name = true;
+ file_is_changed = false;
+ std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
__import_queued_samples();
+ std::cout << "Importing queued samples done.\n" << std::flush;
+
file_structure_changed_signal.emit(this->file);
- return true;
+
+ load_gig(this->file, this->filename.c_str());
+ progress_dialog->hide();
}
void MainWindow::on_action_file_save_as()
@@ -897,28 +1207,28 @@
descriptionArea.show_all();
if (dialog.run() == Gtk::RESPONSE_OK) {
- file_structure_to_be_changed_signal.emit(this->file);
- try {
- std::string filename = dialog.get_filename();
- 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;
+ std::string filename = dialog.get_filename();
+ if (!Glib::str_has_suffix(filename, ".gig")) {
+ filename += ".gig";
}
- __import_queued_samples();
- file_structure_changed_signal.emit(this->file);
+ printf("filename=%s\n", filename.c_str());
+
+ progress_dialog = new ProgressDialog( //FIXME: memory leak!
+ _("Saving") + Glib::ustring(" '") +
+ Glib::filename_display_basename(filename) + "' ...",
+ *this
+ );
+ progress_dialog->show_all();
+
+ saver = new Saver(file, filename); //FIXME: memory leak!
+ saver->signal_progress().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_progress));
+ saver->signal_finished().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_finished));
+ saver->signal_error().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_error));
+ saver->launch();
+
return true;
}
return false;
@@ -1045,8 +1355,8 @@
_(
"Gigedit is released under the GNU General Public License.\n"
"\n"
- "Please notice that this is still a very young instrument editor. "
- "So better backup your Gigasampler files before editing them with "
+ "This program is distributed WITHOUT ANY WARRANTY; So better "
+ "backup your Gigasampler/GigaStudio files before editing them with "
"this application.\n"
"\n"
"Please report bugs to: http://bugs.linuxsampler.org"
@@ -1295,6 +1605,27 @@
}
}
+void MainWindow::updateSampleRefCountMap(gig::File* gig) {
+ sample_ref_count.clear();
+
+ if (!gig) return;
+
+ for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
+ instrument = gig->GetNextInstrument())
+ {
+ for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
+ rgn = instrument->GetNextRegion())
+ {
+ for (int i = 0; i < 256; ++i) {
+ if (!rgn->pDimensionRegions[i]) continue;
+ if (rgn->pDimensionRegions[i]->pSample) {
+ sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
+ }
+ }
+ }
+ }
+}
+
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
{
file = 0;
@@ -1321,7 +1652,9 @@
add_instrument_to_menu(name);
}
instrument_name_connection.unblock();
- uiManager->get_widget("/MenuBar/MenuInstrument")->show();
+ uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
+
+ updateSampleRefCountMap(gig);
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
if (group->Name != "") {
@@ -1339,9 +1672,35 @@
gig_to_utf8(sample->pInfo->Name);
rowSample[m_SamplesModel.m_col_sample] = sample;
rowSample[m_SamplesModel.m_col_group] = NULL;
+ int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
+ rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
+ rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
}
}
}
+
+ for (int i = 0; gig->GetScriptGroup(i); ++i) {
+ gig::ScriptGroup* group = gig->GetScriptGroup(i);
+
+ Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
+ Gtk::TreeModel::Row rowGroup = *iterGroup;
+ rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
+ rowGroup[m_ScriptsModel.m_col_group] = group;
+ rowGroup[m_ScriptsModel.m_col_script] = NULL;
+ for (int s = 0; group->GetScript(s); ++s) {
+ gig::Script* script = group->GetScript(s);
+
+ Gtk::TreeModel::iterator iterScript =
+ m_refScriptsTreeModel->append(rowGroup.children());
+ Gtk::TreeModel::Row rowScript = *iterScript;
+ rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
+ rowScript[m_ScriptsModel.m_col_script] = script;
+ rowScript[m_ScriptsModel.m_col_group] = NULL;
+ }
+ }
+ // unfold all sample groups & script groups by default
+ m_TreeViewSamples.expand_all();
+ m_TreeViewScripts.expand_all();
file = gig;
@@ -1410,6 +1769,22 @@
}
}
+void MainWindow::show_script_slots() {
+ if (!file) return;
+ // get selected instrument
+ Glib::RefPtr sel = m_TreeView.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (!it) return;
+ Gtk::TreeModel::Row row = *it;
+ gig::Instrument* instrument = row[m_Columns.m_col_instr];
+ if (!instrument) return;
+
+ ScriptSlots* window = new ScriptSlots;
+ window->setInstrument(instrument);
+ //window->reparent(*this);
+ window->show();
+}
+
void MainWindow::on_action_view_status_bar() {
Gtk::CheckMenuItem* item =
dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
@@ -1457,9 +1832,15 @@
show_instr_props();
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
// gig v2 files have no midi rules
+ const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
+ static_cast(
+ uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
+ bEnabled
+ );
static_cast(
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
- !(file->pVersion && file->pVersion->major == 2));
+ bEnabled
+ );
popup_menu->popup(button->button, button->time);
}
}
@@ -1493,19 +1874,69 @@
group_selected = row[m_SamplesModel.m_col_group];
sample_selected = row[m_SamplesModel.m_col_sample];
}
+
+
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
set_sensitive(group_selected || sample_selected);
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
set_sensitive(group_selected || sample_selected);
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
set_sensitive(file);
+ dynamic_cast(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
+ set_sensitive(sample_selected);
dynamic_cast(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
set_sensitive(group_selected || sample_selected);
// show sample popup
sample_popup->popup(button->button, button->time);
+
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
+ set_sensitive(group_selected || sample_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
+ set_sensitive(group_selected || sample_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
+ set_sensitive(file);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
+ set_sensitive(sample_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
+ set_sensitive(group_selected || sample_selected);
}
}
+void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
+ if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
+ Gtk::Menu* script_popup =
+ dynamic_cast(uiManager->get_widget("/ScriptPopupMenu"));
+ // update enabled/disabled state of sample popup items
+ Glib::RefPtr sel = m_TreeViewScripts.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ bool group_selected = false;
+ bool script_selected = false;
+ if (it) {
+ Gtk::TreeModel::Row row = *it;
+ group_selected = row[m_ScriptsModel.m_col_group];
+ script_selected = row[m_ScriptsModel.m_col_script];
+ }
+ dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
+ set_sensitive(group_selected || script_selected);
+ dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
+ set_sensitive(file);
+ dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
+ set_sensitive(script_selected);
+ dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
+ set_sensitive(group_selected || script_selected);
+ // show sample popup
+ script_popup->popup(button->button, button->time);
+
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
+ set_sensitive(group_selected || script_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
+ set_sensitive(file);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
+ set_sensitive(script_selected);
+ dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
+ set_sensitive(group_selected || script_selected);
+ }
+}
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
const Glib::ustring& name, int position) {
@@ -1653,6 +2084,118 @@
msg.run();
}
+void MainWindow::on_action_add_script_group() {
+ static int __script_indexer = 0;
+ if (!file) return;
+ gig::ScriptGroup* group = file->AddScriptGroup();
+ group->Name = gig_from_utf8(_("Unnamed Group"));
+ if (__script_indexer) group->Name += " " + ToString(__script_indexer);
+ __script_indexer++;
+ // update sample tree view
+ Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
+ Gtk::TreeModel::Row rowGroup = *iterGroup;
+ rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
+ rowGroup[m_ScriptsModel.m_col_script] = NULL;
+ rowGroup[m_ScriptsModel.m_col_group] = group;
+ file_changed();
+}
+
+void MainWindow::on_action_add_script() {
+ if (!file) return;
+ // get selected group
+ Glib::RefPtr sel = m_TreeViewScripts.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (!it) return;
+ Gtk::TreeModel::Row row = *it;
+ gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
+ if (!group) { // not a group, but a script is selected (probably)
+ gig::Script* script = row[m_ScriptsModel.m_col_script];
+ if (!script) return;
+ it = row.parent(); // resolve parent (that is the script's group)
+ if (!it) return;
+ row = *it;
+ group = row[m_ScriptsModel.m_col_group];
+ if (!group) return;
+ }
+
+ // add a new script to the .gig file
+ gig::Script* script = group->AddScript();
+ Glib::ustring name = _("Unnamed Script");
+ script->Name = gig_from_utf8(name);
+
+ // add script to the tree view
+ Gtk::TreeModel::iterator iterScript =
+ m_refScriptsTreeModel->append(row.children());
+ Gtk::TreeModel::Row rowScript = *iterScript;
+ rowScript[m_ScriptsModel.m_col_name] = name;
+ rowScript[m_ScriptsModel.m_col_script] = script;
+ rowScript[m_ScriptsModel.m_col_group] = NULL;
+
+ // unfold group of new script item in treeview
+ Gtk::TreeModel::Path path(iterScript);
+ m_TreeViewScripts.expand_to_path(path);
+}
+
+void MainWindow::on_action_edit_script() {
+ if (!file) return;
+ // get selected script
+ Glib::RefPtr sel = m_TreeViewScripts.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (!it) return;
+ Gtk::TreeModel::Row row = *it;
+ gig::Script* script = row[m_ScriptsModel.m_col_script];
+ if (!script) return;
+
+ ScriptEditor* editor = new ScriptEditor;
+ editor->setScript(script);
+ //editor->reparent(*this);
+ editor->show();
+}
+
+void MainWindow::on_action_remove_script() {
+ if (!file) return;
+ Glib::RefPtr sel = m_TreeViewScripts.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (it) {
+ Gtk::TreeModel::Row row = *it;
+ gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
+ gig::Script* script = row[m_ScriptsModel.m_col_script];
+ Glib::ustring name = row[m_ScriptsModel.m_col_name];
+ try {
+ // remove script group or script from the gig file
+ if (group) {
+ // notify everybody that we're going to remove these samples
+//TODO: scripts_to_be_removed_signal.emit(members);
+ // delete the group in the .gig file including the
+ // samples that belong to the group
+ file->DeleteScriptGroup(group);
+ // notify that we're done with removal
+//TODO: scripts_removed_signal.emit();
+ file_changed();
+ } else if (script) {
+ // notify everybody that we're going to remove this sample
+//TODO: std::list lscripts;
+//TODO: lscripts.push_back(script);
+//TODO: scripts_to_be_removed_signal.emit(lscripts);
+ // remove sample from the .gig file
+ script->GetGroup()->DeleteScript(script);
+ // notify that we're done with removal
+//TODO: scripts_removed_signal.emit();
+ dimreg_changed();
+ file_changed();
+ }
+ // remove respective row(s) from samples tree view
+ m_refScriptsTreeModel->erase(it);
+ } catch (RIFF::Exception e) {
+ // pretend we're done with removal (i.e. to avoid dead locks)
+//TODO: scripts_removed_signal.emit();
+ // show error message
+ Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
+ msg.run();
+ }
+ }
+}
+
void MainWindow::on_action_add_group() {
static int __sample_indexer = 0;
if (!file) return;
@@ -2022,6 +2565,32 @@
}
}
+// see comment on on_sample_treeview_drag_begin()
+void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr& context)
+{
+ first_call_to_drag_data_get = true;
+}
+
+void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr&,
+ Gtk::SelectionData& selection_data, guint, guint)
+{
+ if (!first_call_to_drag_data_get) return;
+ first_call_to_drag_data_get = false;
+
+ // get selected script
+ gig::Script* script = NULL;
+ Glib::RefPtr sel = m_TreeViewScripts.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (it) {
+ Gtk::TreeModel::Row row = *it;
+ script = row[m_ScriptsModel.m_col_script];
+ }
+ // pass the gig::Script as pointer
+ selection_data.set(selection_data.get_target(), 0/*unused*/,
+ (const guchar*)&script,
+ sizeof(script)/*length of data in bytes*/);
+}
+
// For some reason drag_data_get gets called two times for each
// drag'n'drop (at least when target is an Entry). This work-around
// makes sure the code in drag_data_get and drop_drag_data_received is
@@ -2150,6 +2719,44 @@
}
}
+void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
+ const Gtk::TreeModel::iterator& iter) {
+ if (!iter) return;
+ Gtk::TreeModel::Row row = *iter;
+ Glib::ustring name = row[m_ScriptsModel.m_col_name];
+ gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
+ gig::Script* script = row[m_ScriptsModel.m_col_script];
+ gig::String gigname(gig_from_utf8(name));
+ if (group) {
+ if (group->Name != gigname) {
+ group->Name = gigname;
+ printf("script group name changed\n");
+ file_changed();
+ }
+ } else if (script) {
+ if (script->Name != gigname) {
+ script->Name = gigname;
+ printf("script name changed\n");
+ file_changed();
+ }
+ }
+}
+
+void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
+ Gtk::TreeViewColumn* column)
+{
+ Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
+ if (!iter) return;
+ Gtk::TreeModel::Row row = *iter;
+ gig::Script* script = row[m_ScriptsModel.m_col_script];
+ if (!script) return;
+
+ ScriptEditor* editor = new ScriptEditor;
+ editor->setScript(script);
+ //editor->reparent(*this);
+ editor->show();
+}
+
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
const Gtk::TreeModel::iterator& iter) {
if (!iter) return;
@@ -2196,6 +2803,22 @@
delete d;
}
+void MainWindow::on_action_view_references() {
+ Glib::RefPtr sel = m_TreeViewSamples.get_selection();
+ Gtk::TreeModel::iterator it = sel->get_selected();
+ if (!it) return;
+ Gtk::TreeModel::Row row = *it;
+ gig::Sample* sample = row[m_SamplesModel.m_col_sample];
+ if (!sample) return;
+
+ ReferencesView* d = new ReferencesView(*this);
+ d->setSample(sample);
+ d->show_all();
+ d->resize(500, 400);
+ d->run();
+ delete d;
+}
+
void MainWindow::mergeFiles(const std::vector& filenames) {
struct _Source {
std::vector riffs;
@@ -2263,8 +2886,27 @@
);
}
- // Note: requires that this file already has a filename !
- this->file->Save();
+ // Finally save gig file persistently to disk ...
+ //NOTE: requires that this gig file already has a filename !
+ {
+ std::cout << "Saving file\n" << std::flush;
+ file_structure_to_be_changed_signal.emit(this->file);
+
+ progress_dialog = new ProgressDialog( //FIXME: memory leak!
+ _("Saving") + Glib::ustring(" '") +
+ Glib::filename_display_basename(this->filename) + "' ...",
+ *this
+ );
+ progress_dialog->show_all();
+ saver = new Saver(this->file); //FIXME: memory leak!
+ saver->signal_progress().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_progress));
+ saver->signal_finished().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_finished));
+ saver->signal_error().connect(
+ sigc::mem_fun(*this, &MainWindow::on_saver_error));
+ saver->launch();
+ }
}
void MainWindow::on_action_merge_files() {
@@ -2356,6 +2998,50 @@
}
}
+void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
+ if (!sample) return;
+ sample_ref_count[sample] += offset;
+ const int refcount = sample_ref_count[sample];
+
+ Glib::RefPtr model = m_TreeViewSamples.get_model();
+ for (int g = 0; g < model->children().size(); ++g) {
+ Gtk::TreeModel::Row rowGroup = model->children()[g];
+ for (int s = 0; s < rowGroup.children().size(); ++s) {
+ Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
+ if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
+ rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
+ rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
+ }
+ }
+}
+
+void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
+ on_sample_ref_count_incremented(oldSample, -1);
+ on_sample_ref_count_incremented(newSample, +1);
+}
+
+void MainWindow::on_samples_to_be_removed(std::list samples) {
+ // just in case a new sample is added later with exactly the same memory
+ // address, which would lead to incorrect refcount if not deleted here
+ for (std::list::const_iterator it = samples.begin();
+ it != samples.end(); ++it)
+ {
+ sample_ref_count.erase(*it);
+ }
+}
+
+void MainWindow::show_samples_tab() {
+ m_TreeViewNotebook.set_current_page(0);
+}
+
+void MainWindow::show_intruments_tab() {
+ m_TreeViewNotebook.set_current_page(1);
+}
+
+void MainWindow::show_scripts_tab() {
+ m_TreeViewNotebook.set_current_page(2);
+}
+
sigc::signal& MainWindow::signal_file_structure_to_be_changed() {
return file_structure_to_be_changed_signal;
}