1 |
/* |
/* |
2 |
* Copyright (C) 2006-2016 Andreas Persson |
* Copyright (C) 2006-2017 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 |
57 |
#include "ReferencesView.h" |
#include "ReferencesView.h" |
58 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
59 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
60 |
|
#include "gfx/builtinpix.h" |
61 |
|
|
62 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
63 |
m_DimRegionChooser(*this), |
m_DimRegionChooser(*this), |
64 |
dimreg_label(_("Changes apply to:")), |
dimreg_label(_("Changes apply to:")), |
65 |
dimreg_all_regions(_("all regions")), |
dimreg_all_regions(_("all regions")), |
66 |
dimreg_all_dimregs(_("all dimension splits")), |
dimreg_all_dimregs(_("all dimension splits")), |
67 |
dimreg_stereo(_("both channels")) |
dimreg_stereo(_("both channels")), |
68 |
|
labelLegend(_("Legend:")), |
69 |
|
labelNoSample(_(" No Sample")), |
70 |
|
labelMissingSample(_(" Missing some Sample(s)")), |
71 |
|
labelLooped(_(" Looped")), |
72 |
|
labelSomeLoops(_(" Some Loop(s)")) |
73 |
{ |
{ |
74 |
|
loadBuiltInPix(); |
75 |
|
|
76 |
// set_border_width(5); |
// set_border_width(5); |
77 |
// set_default_size(400, 200); |
// set_default_size(400, 200); |
78 |
|
|
|
|
|
79 |
add(m_VBox); |
add(m_VBox); |
80 |
|
|
81 |
// Handle selection |
// Handle selection |
109 |
dimreg_hbox.add(dimreg_stereo); |
dimreg_hbox.add(dimreg_stereo); |
110 |
dimreg_vbox.add(dimreg_edit); |
dimreg_vbox.add(dimreg_edit); |
111 |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
112 |
|
{ |
113 |
|
legend_hbox.add(labelLegend); |
114 |
|
|
115 |
|
imageNoSample.set(redDot); |
116 |
|
imageNoSample.set_alignment(Gtk::ALIGN_END); |
117 |
|
labelNoSample.set_alignment(Gtk::ALIGN_START); |
118 |
|
legend_hbox.add(imageNoSample); |
119 |
|
legend_hbox.add(labelNoSample); |
120 |
|
|
121 |
|
imageMissingSample.set(yellowDot); |
122 |
|
imageMissingSample.set_alignment(Gtk::ALIGN_END); |
123 |
|
labelMissingSample.set_alignment(Gtk::ALIGN_START); |
124 |
|
legend_hbox.add(imageMissingSample); |
125 |
|
legend_hbox.add(labelMissingSample); |
126 |
|
|
127 |
|
imageLooped.set(blackLoop); |
128 |
|
imageLooped.set_alignment(Gtk::ALIGN_END); |
129 |
|
labelLooped.set_alignment(Gtk::ALIGN_START); |
130 |
|
legend_hbox.add(imageLooped); |
131 |
|
legend_hbox.add(labelLooped); |
132 |
|
|
133 |
|
imageSomeLoops.set(grayLoop); |
134 |
|
imageSomeLoops.set_alignment(Gtk::ALIGN_END); |
135 |
|
labelSomeLoops.set_alignment(Gtk::ALIGN_START); |
136 |
|
legend_hbox.add(imageSomeLoops); |
137 |
|
legend_hbox.add(labelSomeLoops); |
138 |
|
|
139 |
|
legend_hbox.show_all_children(); |
140 |
|
} |
141 |
|
dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK); |
142 |
m_HPaned.add2(dimreg_vbox); |
m_HPaned.add2(dimreg_vbox); |
143 |
|
|
144 |
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
557 |
// Create the Tree model: |
// Create the Tree model: |
558 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
559 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
560 |
|
m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
561 |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); |
562 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
563 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
564 |
); |
); |
565 |
|
|
566 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
567 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr); |
568 |
m_TreeView.set_headers_visible(false); |
m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name); |
569 |
|
m_TreeView.set_headers_visible(true); |
570 |
|
|
571 |
// establish drag&drop within the instrument tree view, allowing to reorder |
// establish drag&drop within the instrument tree view, allowing to reorder |
572 |
// the sequence of instruments within the gig file |
// the sequence of instruments within the gig file |
589 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
590 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
591 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
592 |
|
m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); |
593 |
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_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.")); |
594 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
595 |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
767 |
gig::Instrument* MainWindow::get_instrument() |
gig::Instrument* MainWindow::get_instrument() |
768 |
{ |
{ |
769 |
gig::Instrument* instrument = 0; |
gig::Instrument* instrument = 0; |
770 |
Gtk::TreeModel::const_iterator it = |
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
771 |
m_TreeView.get_selection()->get_selected(); |
if (rows.empty()) return NULL; |
772 |
|
Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); |
773 |
if (it) { |
if (it) { |
774 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
775 |
instrument = row[m_Columns.m_col_instr]; |
instrument = row[m_Columns.m_col_instr]; |
812 |
add_region_to_dimregs(region, stereo, all_dimregs); |
add_region_to_dimregs(region, stereo, all_dimregs); |
813 |
} |
} |
814 |
} |
} |
815 |
|
|
816 |
|
m_DimRegionChooser.setModifyAllRegions(all_regions); |
817 |
|
m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs); |
818 |
|
m_DimRegionChooser.setModifyBothChannels(stereo); |
819 |
} |
} |
820 |
|
|
821 |
void MainWindow::dimreg_all_dimregs_toggled() |
void MainWindow::dimreg_all_dimregs_toggled() |
833 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
834 |
{ |
{ |
835 |
// select item in instrument menu |
// select item in instrument menu |
836 |
Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
837 |
if (it) { |
if (!rows.empty()) { |
838 |
Gtk::TreePath path(it); |
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); |
839 |
int index = path[0]; |
if (it) { |
840 |
const std::vector<Gtk::Widget*> children = |
Gtk::TreePath path(it); |
841 |
instrument_menu->get_children(); |
int index = path[0]; |
842 |
static_cast<Gtk::RadioMenuItem*>(children[index])->set_active(); |
const std::vector<Gtk::Widget*> children = |
843 |
|
instrument_menu->get_children(); |
844 |
|
static_cast<Gtk::RadioMenuItem*>(children[index])->set_active(); |
845 |
|
} |
846 |
} |
} |
847 |
|
|
848 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
867 |
progress_dispatcher(); |
progress_dispatcher(); |
868 |
} |
} |
869 |
|
|
870 |
|
#if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) |
871 |
|
// make sure stack is 16-byte aligned for SSE instructions |
872 |
|
__attribute__((force_align_arg_pointer)) |
873 |
|
#endif |
874 |
void Loader::thread_function() |
void Loader::thread_function() |
875 |
{ |
{ |
876 |
printf("thread_function self=%p\n", |
printf("thread_function self=%p\n", |
950 |
progress_dispatcher.emit(); |
progress_dispatcher.emit(); |
951 |
} |
} |
952 |
|
|
953 |
|
#if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) |
954 |
|
// make sure stack is 16-byte aligned for SSE instructions |
955 |
|
__attribute__((force_align_arg_pointer)) |
956 |
|
#endif |
957 |
void Saver::thread_function() |
void Saver::thread_function() |
958 |
{ |
{ |
959 |
printf("thread_function self=%p\n", |
printf("thread_function self=%p\n", |
1448 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1449 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1450 |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1451 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1452 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1453 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",iter->second.sample_path.c_str()); |
1454 |
SF_INFO info; |
SF_INFO info; |
1455 |
info.format = 0; |
info.format = 0; |
1456 |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info); |
1457 |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
1458 |
try { |
try { |
1459 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
1476 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1477 |
} |
} |
1478 |
|
|
1479 |
|
// reset write position for sample |
1480 |
|
iter->first->SetPos(0); |
1481 |
|
|
1482 |
const int bufsize = 10000; |
const int bufsize = 10000; |
1483 |
switch (bitdepth) { |
switch (bitdepth) { |
1484 |
case 16: { |
case 16: { |
1488 |
// libsndfile does the conversion for us (if needed) |
// libsndfile does the conversion for us (if needed) |
1489 |
int n = sf_readf_short(hFile, buffer, bufsize); |
int n = sf_readf_short(hFile, buffer, bufsize); |
1490 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1491 |
iter->gig_sample->Write(buffer, n); |
iter->first->Write(buffer, n); |
1492 |
cnt -= n; |
cnt -= n; |
1493 |
} |
} |
1494 |
delete[] buffer; |
delete[] buffer; |
1508 |
dstbuf[j++] = srcbuf[i] >> 24; |
dstbuf[j++] = srcbuf[i] >> 24; |
1509 |
} |
} |
1510 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1511 |
iter->gig_sample->Write(dstbuf, n); |
iter->first->Write(dstbuf, n); |
1512 |
cnt -= n; |
cnt -= n; |
1513 |
} |
} |
1514 |
delete[] srcbuf; |
delete[] srcbuf; |
1519 |
// cleanup |
// cleanup |
1520 |
sf_close(hFile); |
sf_close(hFile); |
1521 |
// let the sampler re-cache the sample if needed |
// let the sampler re-cache the sample if needed |
1522 |
sample_changed_signal.emit(iter->gig_sample); |
sample_changed_signal.emit(iter->first); |
1523 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
1524 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
1525 |
std::list<SampleImportItem>::iterator cur = iter; |
std::map<gig::Sample*, SampleImportItem>::iterator cur = iter; |
1526 |
++iter; |
++iter; |
1527 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
1528 |
} catch (std::string what) { |
} catch (std::string what) { |
1529 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
1530 |
if (!error_files.empty()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1531 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += iter->second.sample_path += " (" + what + ")"; |
1532 |
++iter; |
++iter; |
1533 |
} |
} |
1534 |
} |
} |
1570 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1571 |
#endif |
#endif |
1572 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1573 |
dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson"); |
1574 |
const std::string sComment = |
const std::string sComment = |
1575 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1576 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1865 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1866 |
|
|
1867 |
instrument_name_connection.block(); |
instrument_name_connection.block(); |
1868 |
|
int index = 0; |
1869 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
1870 |
instrument = gig->GetNextInstrument()) { |
instrument = gig->GetNextInstrument(), ++index) { |
1871 |
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1872 |
|
|
1873 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
1874 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1875 |
|
row[m_Columns.m_col_nr] = index; |
1876 |
row[m_Columns.m_col_name] = name; |
row[m_Columns.m_col_name] = name; |
1877 |
row[m_Columns.m_col_instr] = instrument; |
row[m_Columns.m_col_instr] = instrument; |
1878 |
|
|
1945 |
{ |
{ |
1946 |
instrumentProps.signal_name_changed().clear(); |
instrumentProps.signal_name_changed().clear(); |
1947 |
|
|
1948 |
Gtk::TreeModel::const_iterator it = |
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
1949 |
m_TreeView.get_selection()->get_selected(); |
if (rows.empty()) { |
1950 |
|
instrumentProps.hide(); |
1951 |
|
return false; |
1952 |
|
} |
1953 |
|
Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); |
1954 |
if (it) { |
if (it) { |
1955 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
1956 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
2003 |
void MainWindow::show_script_slots() { |
void MainWindow::show_script_slots() { |
2004 |
if (!file) return; |
if (!file) return; |
2005 |
// get selected instrument |
// get selected instrument |
2006 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows(); |
2007 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
if (rows.empty()) return; |
2008 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); |
2009 |
if (!it) return; |
if (!it) return; |
2010 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2011 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
2125 |
if (row[m_Columns.m_col_instr] == instrument) { |
if (row[m_Columns.m_col_instr] == instrument) { |
2126 |
// select and show the respective instrument in the list view |
// select and show the respective instrument in the list view |
2127 |
show_intruments_tab(); |
show_intruments_tab(); |
2128 |
|
m_TreeView.get_selection()->unselect_all(); |
2129 |
m_TreeView.get_selection()->select(model->children()[i]); |
m_TreeView.get_selection()->select(model->children()[i]); |
2130 |
Gtk::TreePath path( |
std::vector<Gtk::TreeModel::Path> rows = |
2131 |
m_TreeView.get_selection()->get_selected() |
m_TreeView.get_selection()->get_selected_rows(); |
2132 |
); |
if (!rows.empty()) |
2133 |
m_TreeView.scroll_to_row(path); |
m_TreeView.scroll_to_row(rows[0]); |
2134 |
on_sel_change(); // the regular instrument selection change callback |
on_sel_change(); // the regular instrument selection change callback |
2135 |
} |
} |
2136 |
} |
} |
2147 |
if (row[m_Columns.m_col_instr] == pInstrument) { |
if (row[m_Columns.m_col_instr] == pInstrument) { |
2148 |
// select and show the respective instrument in the list view |
// select and show the respective instrument in the list view |
2149 |
show_intruments_tab(); |
show_intruments_tab(); |
2150 |
|
m_TreeView.get_selection()->unselect_all(); |
2151 |
m_TreeView.get_selection()->select(model->children()[i]); |
m_TreeView.get_selection()->select(model->children()[i]); |
2152 |
Gtk::TreePath path( |
std::vector<Gtk::TreeModel::Path> rows = |
2153 |
m_TreeView.get_selection()->get_selected() |
m_TreeView.get_selection()->get_selected_rows(); |
2154 |
); |
if (!rows.empty()) |
2155 |
m_TreeView.scroll_to_row(path); |
m_TreeView.scroll_to_row(rows[0]); |
2156 |
on_sel_change(); // the regular instrument selection change callback |
on_sel_change(); // the regular instrument selection change callback |
2157 |
|
|
2158 |
// select respective region in the region selector |
// select respective region in the region selector |
2178 |
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2179 |
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
2180 |
show_samples_tab(); |
show_samples_tab(); |
2181 |
|
m_TreeViewSamples.get_selection()->unselect_all(); |
2182 |
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
2183 |
Gtk::TreePath path( |
std::vector<Gtk::TreeModel::Path> rows = |
2184 |
m_TreeViewSamples.get_selection()->get_selected() |
m_TreeViewSamples.get_selection()->get_selected_rows(); |
2185 |
); |
if (rows.empty()) return; |
2186 |
m_TreeViewSamples.scroll_to_row(path); |
m_TreeViewSamples.scroll_to_row(rows[0]); |
2187 |
return; |
return; |
2188 |
} |
} |
2189 |
} |
} |
2192 |
|
|
2193 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
2194 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2195 |
|
// by default if Ctrl keys is pressed down, then a mouse right-click |
2196 |
|
// does not select the respective row, so we must assure this |
2197 |
|
// programmatically ... |
2198 |
|
/*{ |
2199 |
|
Gtk::TreeModel::Path path; |
2200 |
|
Gtk::TreeViewColumn* pColumn = NULL; |
2201 |
|
int cellX, cellY; |
2202 |
|
bool bSuccess = m_TreeViewSamples.get_path_at_pos( |
2203 |
|
(int)button->x, (int)button->y, |
2204 |
|
path, pColumn, cellX, cellY |
2205 |
|
); |
2206 |
|
if (bSuccess) { |
2207 |
|
if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) { |
2208 |
|
printf("not selected !!!\n"); |
2209 |
|
m_TreeViewSamples.get_selection()->select(path); |
2210 |
|
} |
2211 |
|
} |
2212 |
|
}*/ |
2213 |
|
|
2214 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
2215 |
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu")); |
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu")); |
2216 |
// update enabled/disabled state of sample popup items |
// update enabled/disabled state of sample popup items |
2217 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2218 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2219 |
bool group_selected = false; |
const int n = rows.size(); |
2220 |
bool sample_selected = false; |
int nGroups = 0; |
2221 |
if (it) { |
int nSamples = 0; |
2222 |
|
for (int r = 0; r < n; ++r) { |
2223 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]); |
2224 |
|
if (!it) continue; |
2225 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2226 |
group_selected = row[m_SamplesModel.m_col_group]; |
if (row[m_SamplesModel.m_col_group]) nGroups++; |
2227 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
if (row[m_SamplesModel.m_col_sample]) nSamples++; |
2228 |
} |
} |
2229 |
|
|
|
|
|
2230 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
2231 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n == 1); |
2232 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
2233 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n); |
2234 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
2235 |
set_sensitive(file); |
set_sensitive(file); |
2236 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
2237 |
set_sensitive(sample_selected); |
set_sensitive(nSamples == 1); |
2238 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
2239 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n); |
2240 |
// show sample popup |
// show sample popup |
2241 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
2242 |
|
|
2243 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
2244 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n == 1); |
2245 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
2246 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n); |
2247 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
2248 |
set_sensitive(file); |
set_sensitive(file); |
2249 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
2250 |
set_sensitive(sample_selected); |
set_sensitive(nSamples == 1); |
2251 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
2252 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(n); |
2253 |
} |
} |
2254 |
} |
} |
2255 |
|
|
2328 |
instrument_name_connection.block(); |
instrument_name_connection.block(); |
2329 |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
2330 |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
2331 |
|
rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1; |
2332 |
rowInstr[m_Columns.m_col_name] = name; |
rowInstr[m_Columns.m_col_name] = name; |
2333 |
rowInstr[m_Columns.m_col_instr] = instrument; |
rowInstr[m_Columns.m_col_instr] = instrument; |
2334 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
2357 |
// retrieve the currently selected instrument |
// retrieve the currently selected instrument |
2358 |
// (being the original instrument to be duplicated) |
// (being the original instrument to be duplicated) |
2359 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2360 |
Gtk::TreeModel::iterator itSelection = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2361 |
if (!itSelection) return; |
for (int r = 0; r < rows.size(); ++r) { |
2362 |
Gtk::TreeModel::Row row = *itSelection; |
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]); |
2363 |
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
if (it) { |
2364 |
if (!instrOrig) return; |
Gtk::TreeModel::Row row = *it; |
2365 |
|
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
2366 |
// duplicate the orginal instrument |
if (instrOrig) { |
2367 |
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
// duplicate the orginal instrument |
2368 |
instrNew->pInfo->Name = |
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
2369 |
instrOrig->pInfo->Name + |
instrNew->pInfo->Name = |
2370 |
gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); |
instrOrig->pInfo->Name + |
2371 |
|
gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); |
2372 |
|
|
2373 |
add_instrument(instrNew); |
add_instrument(instrNew); |
2374 |
|
} |
2375 |
|
} |
2376 |
|
} |
2377 |
} |
} |
2378 |
|
|
2379 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
2390 |
} |
} |
2391 |
|
|
2392 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2393 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2394 |
if (it) { |
for (int r = rows.size() - 1; r >= 0; --r) { |
2395 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]); |
2396 |
|
if (!it) continue; |
2397 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2398 |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
2399 |
try { |
try { |
2408 |
|
|
2409 |
// remove row from instruments tree view |
// remove row from instruments tree view |
2410 |
m_refTreeModel->erase(it); |
m_refTreeModel->erase(it); |
2411 |
|
// update "Nr" column of all instrument rows |
2412 |
|
{ |
2413 |
|
int index = 0; |
2414 |
|
for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin(); |
2415 |
|
it != m_refTreeModel->children().end(); ++it, ++index) |
2416 |
|
{ |
2417 |
|
Gtk::TreeModel::Row row = *it; |
2418 |
|
row[m_Columns.m_col_nr] = index; |
2419 |
|
} |
2420 |
|
} |
2421 |
|
|
2422 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
2423 |
// select another instrument (in gtk3 this is done |
// select another instrument (in gtk3 this is done |
2599 |
|
|
2600 |
// get selected group (and probably selected sample) |
// get selected group (and probably selected sample) |
2601 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2602 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2603 |
|
if (rows.empty()) return; |
2604 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); |
2605 |
if (!it) return; |
if (!it) return; |
2606 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2607 |
gig::Sample* sample = NULL; |
gig::Sample* sample = NULL; |
2750 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2751 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
2752 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2753 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
2754 |
// add sample to the tree view |
// add sample to the tree view |
2755 |
if (replace) { |
if (replace) { |
2756 |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
2860 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2861 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
2862 |
sched_item.sample_path = filename; |
sched_item.sample_path = filename; |
2863 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
2864 |
sf_close(hFile); |
sf_close(hFile); |
2865 |
file_changed(); |
file_changed(); |
2866 |
} |
} |
2884 |
void MainWindow::on_action_remove_sample() { |
void MainWindow::on_action_remove_sample() { |
2885 |
if (!file) return; |
if (!file) return; |
2886 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2887 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
2888 |
if (it) { |
for (int r = rows.size() - 1; r >= 0; --r) { |
2889 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]); |
2890 |
|
if (!it) continue; |
2891 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2892 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2893 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2912 |
// if sample(s) were just previously added, remove |
// if sample(s) were just previously added, remove |
2913 |
// them from the import queue |
// them from the import queue |
2914 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
2915 |
member != members.end(); ++member) { |
member != members.end(); ++member) |
2916 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
{ |
2917 |
iter != m_SampleImportQueue.end(); ++iter) { |
if (m_SampleImportQueue.count(*member)) { |
2918 |
if ((*iter).gig_sample == *member) { |
printf("Removing previously added sample '%s' from group '%s'\n", |
2919 |
printf("Removing previously added sample '%s' from group '%s'\n", |
m_SampleImportQueue[sample].sample_path.c_str(), name.c_str()); |
2920 |
(*iter).sample_path.c_str(), name.c_str()); |
m_SampleImportQueue.erase(*member); |
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
2921 |
} |
} |
2922 |
} |
} |
2923 |
file_changed(); |
file_changed(); |
2932 |
samples_removed_signal.emit(); |
samples_removed_signal.emit(); |
2933 |
// if sample was just previously added, remove it from |
// if sample was just previously added, remove it from |
2934 |
// the import queue |
// the import queue |
2935 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
2936 |
iter != m_SampleImportQueue.end(); ++iter) { |
printf("Removing previously added sample '%s'\n", |
2937 |
if ((*iter).gig_sample == sample) { |
m_SampleImportQueue[sample].sample_path.c_str()); |
2938 |
printf("Removing previously added sample '%s'\n", |
m_SampleImportQueue.erase(sample); |
|
(*iter).sample_path.c_str()); |
|
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
2939 |
} |
} |
2940 |
dimreg_changed(); |
dimreg_changed(); |
2941 |
file_changed(); |
file_changed(); |
2991 |
gig::Sample* sample = *itSample; |
gig::Sample* sample = *itSample; |
2992 |
// remove sample from the .gig file |
// remove sample from the .gig file |
2993 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
2994 |
// if sample was just previously added, remove it fro the import queue |
// if sample was just previously added, remove it from the import queue |
2995 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
2996 |
iter != m_SampleImportQueue.end(); ++iter) |
printf("Removing previously added sample '%s'\n", |
2997 |
{ |
m_SampleImportQueue[sample].sample_path.c_str()); |
2998 |
if ((*iter).gig_sample == sample) { |
m_SampleImportQueue.erase(sample); |
|
printf("Removing previously added sample '%s'\n", |
|
|
(*iter).sample_path.c_str()); |
|
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
2999 |
} |
} |
3000 |
} |
} |
3001 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
3054 |
gig::Instrument* src = NULL; |
gig::Instrument* src = NULL; |
3055 |
{ |
{ |
3056 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
3057 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
3058 |
if (it) { |
if (!rows.empty()) { |
3059 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); |
3060 |
src = row[m_Columns.m_col_instr]; |
if (it) { |
3061 |
|
Gtk::TreeModel::Row row = *it; |
3062 |
|
src = row[m_Columns.m_col_instr]; |
3063 |
|
} |
3064 |
} |
} |
3065 |
} |
} |
3066 |
if (!src) return; |
if (!src) return; |
3115 |
// get selected sample |
// get selected sample |
3116 |
gig::Sample* sample = NULL; |
gig::Sample* sample = NULL; |
3117 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
3118 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
3119 |
if (it) { |
if (!rows.empty()) { |
3120 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); |
3121 |
sample = row[m_SamplesModel.m_col_sample]; |
if (it) { |
3122 |
|
Gtk::TreeModel::Row row = *it; |
3123 |
|
sample = row[m_SamplesModel.m_col_sample]; |
3124 |
|
} |
3125 |
} |
} |
3126 |
// pass the gig::Sample as pointer |
// pass the gig::Sample as pointer |
3127 |
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, |
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, |
3320 |
|
|
3321 |
void MainWindow::on_action_view_references() { |
void MainWindow::on_action_view_references() { |
3322 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
3323 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
3324 |
|
if (rows.empty()) return; |
3325 |
|
Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); |
3326 |
if (!it) return; |
if (!it) return; |
3327 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
3328 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |