28 |
#define ABOUT_DIALOG |
#define ABOUT_DIALOG |
29 |
#include <gtkmm/aboutdialog.h> |
#include <gtkmm/aboutdialog.h> |
30 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
31 |
|
#include <gtkmm/targetentry.h> |
32 |
#endif |
#endif |
33 |
|
|
34 |
#include <stdio.h> |
#include <stdio.h> |
391 |
|
|
392 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
393 |
// eSample("Sample", wSample), |
// eSample("Sample", wSample), |
|
eVelocityUpperLimit("VelocityUpperLimit", |
|
|
&gig::DimensionRegion::VelocityUpperLimit), |
|
394 |
eEG1PreAttack("PreAttack", &gig::DimensionRegion::EG1PreAttack, 0, 100, 2), |
eEG1PreAttack("PreAttack", &gig::DimensionRegion::EG1PreAttack, 0, 100, 2), |
395 |
eEG1Attack("Attack", &gig::DimensionRegion::EG1Attack, 0, 60, 3), |
eEG1Attack("Attack", &gig::DimensionRegion::EG1Attack, 0, 60, 3), |
396 |
eEG1Decay1("Decay1", &gig::DimensionRegion::EG1Decay1, 0.005, 60, 3), |
eEG1Decay1("Decay1", &gig::DimensionRegion::EG1Decay1, 0.005, 60, 3), |
551 |
firstRowInBlock = 0; |
firstRowInBlock = 0; |
552 |
|
|
553 |
addString("Sample", lSample, wSample); |
addString("Sample", lSample, wSample); |
554 |
addProp(eVelocityUpperLimit); |
//TODO: the following would break drag&drop: wSample->property_editable().set_value(false); or this: wSample->set_editable(false); |
555 |
addHeader("EG1"); |
addHeader("EG1"); |
556 |
addProp(eEG1PreAttack); |
addProp(eEG1PreAttack); |
557 |
addProp(eEG1Attack); |
addProp(eEG1Attack); |
924 |
// Create the Tree model: |
// Create the Tree model: |
925 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
926 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
927 |
|
m_refTreeModel->signal_row_changed().connect( |
928 |
|
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
929 |
|
); |
930 |
|
|
931 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
932 |
m_TreeView.append_column("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
933 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
934 |
|
|
935 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
936 |
m_refSamplesTreeModel = Gtk::TreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
937 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
938 |
m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
939 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.set_headers_visible(false); |
940 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
941 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
942 |
); |
); |
943 |
|
m_refSamplesTreeModel->signal_row_changed().connect( |
944 |
|
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
945 |
|
); |
946 |
|
|
947 |
|
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
948 |
|
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
949 |
|
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
950 |
|
//drag_target_gig_sample.push_back( Gtk::TargetEntry("STRING") ); |
951 |
|
//drag_target_gig_sample.push_back( Gtk::TargetEntry("text/plain") ); |
952 |
|
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
953 |
|
m_TreeViewSamples.signal_drag_data_get().connect( |
954 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
955 |
|
); |
956 |
|
wSample->drag_dest_set(drag_target_gig_sample); |
957 |
|
wSample->signal_drag_data_received().connect( |
958 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
959 |
|
); |
960 |
|
|
961 |
file = 0; |
file = 0; |
962 |
|
|
996 |
{ |
{ |
997 |
update_gui = false; |
update_gui = false; |
998 |
wSample->set_text(d->pSample ? d->pSample->pInfo->Name.c_str() : "NULL"); |
wSample->set_text(d->pSample ? d->pSample->pInfo->Name.c_str() : "NULL"); |
|
eVelocityUpperLimit.set_dimreg(d); |
|
999 |
eEG1PreAttack.set_dimreg(d); |
eEG1PreAttack.set_dimreg(d); |
1000 |
eEG1Attack.set_dimreg(d); |
eEG1Attack.set_dimreg(d); |
1001 |
eEG1Decay1.set_dimreg(d); |
eEG1Decay1.set_dimreg(d); |
1367 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1368 |
{ |
{ |
1369 |
if (!file) return; |
if (!file) return; |
1370 |
file->Save(); |
std::cout << "Saving file\n" << std::flush; |
1371 |
|
try { |
1372 |
|
file->Save(); |
1373 |
|
} catch (RIFF::Exception e) { |
1374 |
|
Glib::ustring txt = "Could not save file: " + e.Message; |
1375 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1376 |
|
msg.run(); |
1377 |
|
return; |
1378 |
|
} |
1379 |
|
std::cout << "Saving file done\n" << std::flush; |
1380 |
__import_queued_samples(); |
__import_queued_samples(); |
1381 |
} |
} |
1382 |
|
|
1391 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
1392 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1393 |
printf("filename=%s\n", dialog.get_filename().c_str()); |
printf("filename=%s\n", dialog.get_filename().c_str()); |
1394 |
file->Save(dialog.get_filename()); |
try { |
1395 |
|
file->Save(dialog.get_filename()); |
1396 |
|
} catch (RIFF::Exception e) { |
1397 |
|
Glib::ustring txt = "Could not save file: " + e.Message; |
1398 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1399 |
|
msg.run(); |
1400 |
|
return; |
1401 |
|
} |
1402 |
__import_queued_samples(); |
__import_queued_samples(); |
1403 |
} |
} |
1404 |
} |
} |
1405 |
|
|
1406 |
// actually write the sample(s)' data to the gig file |
// actually write the sample(s)' data to the gig file |
1407 |
void MainWindow::__import_queued_samples() { |
void MainWindow::__import_queued_samples() { |
1408 |
|
std::cout << "Starting sample import\n" << std::flush; |
1409 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1410 |
|
printf("Samples to import: %d\n", m_SampleImportQueue.size()); |
1411 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ) { |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ) { |
1412 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1413 |
SF_INFO info; |
SF_INFO info; |
1929 |
} |
} |
1930 |
} |
} |
1931 |
} |
} |
1932 |
|
|
1933 |
|
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, Gtk::SelectionData& selection_data, guint, guint) |
1934 |
|
{ |
1935 |
|
// get selected sample |
1936 |
|
gig::Sample* sample = NULL; |
1937 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1938 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1939 |
|
if (it) { |
1940 |
|
Gtk::TreeModel::Row row = *it; |
1941 |
|
sample = row[m_SamplesModel.m_col_sample]; |
1942 |
|
} |
1943 |
|
// pass the gig::Sample as pointer |
1944 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, sizeof(sample)/*length of data in bytes*/); |
1945 |
|
} |
1946 |
|
|
1947 |
|
void MainWindow::on_sample_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time) |
1948 |
|
{ |
1949 |
|
gig::DimensionRegion* dimregion = m_DimRegionChooser.get_dimregion(); |
1950 |
|
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
1951 |
|
|
1952 |
|
if (sample && dimregion && selection_data.get_length() == sizeof(gig::Sample*)) { |
1953 |
|
if (sample != dimregion->pSample) { |
1954 |
|
dimregion->pSample = sample; |
1955 |
|
wSample->set_text(dimregion->pSample->pInfo->Name.c_str()); |
1956 |
|
std::cout << "Drop received sample \"" << dimregion->pSample->pInfo->Name.c_str() << "\"" << std::endl; |
1957 |
|
// drop success |
1958 |
|
context->drop_reply(true, time); |
1959 |
|
return; |
1960 |
|
} |
1961 |
|
} |
1962 |
|
// drop failed |
1963 |
|
context->drop_reply(false, time); |
1964 |
|
} |
1965 |
|
|
1966 |
|
void MainWindow::sample_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter) { |
1967 |
|
if (!iter) return; |
1968 |
|
Gtk::TreeModel::Row row = *iter; |
1969 |
|
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
1970 |
|
gig::Group* group = row[m_SamplesModel.m_col_group]; |
1971 |
|
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
1972 |
|
if (group) { |
1973 |
|
group->Name = name; |
1974 |
|
std::cout << "Group name changed\n" << std::flush; |
1975 |
|
} else if (sample) { |
1976 |
|
sample->pInfo->Name = name.raw(); |
1977 |
|
std::cout << "Sample name changed\n" << std::flush; |
1978 |
|
} |
1979 |
|
} |
1980 |
|
|
1981 |
|
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter) { |
1982 |
|
std::cout << "Instrument name changed\n" << std::flush; |
1983 |
|
if (!iter) return; |
1984 |
|
Gtk::TreeModel::Row row = *iter; |
1985 |
|
Glib::ustring name = row[m_Columns.m_col_name]; |
1986 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1987 |
|
if (instrument) instrument->pInfo->Name = name.raw(); |
1988 |
|
} |