520 |
eSampleLoops("SampleLoops", &access_SampleLoops, 0, 1) |
eSampleLoops("SampleLoops", &access_SampleLoops, 0, 1) |
521 |
{ |
{ |
522 |
// set_border_width(5); |
// set_border_width(5); |
523 |
set_default_size(400, 200); |
// set_default_size(400, 200); |
524 |
|
|
525 |
|
|
526 |
add(m_VBox); |
add(m_VBox); |
534 |
sigc::mem_fun(*this, &MainWindow::on_button_release)); |
sigc::mem_fun(*this, &MainWindow::on_button_release)); |
535 |
|
|
536 |
// Add the TreeView tab, inside a ScrolledWindow, with the button underneath: |
// Add the TreeView tab, inside a ScrolledWindow, with the button underneath: |
537 |
m_ScrolledWindow.add(m_TreeViewNotebook); |
m_ScrolledWindow.add(m_TreeView); |
538 |
m_ScrolledWindow.set_size_request(400, 600); |
// m_ScrolledWindow.set_size_request(200, 600); |
539 |
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
540 |
|
|
541 |
|
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
542 |
|
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
543 |
|
|
544 |
|
|
545 |
for (int i = 0 ; i < 5 ; i++) { |
for (int i = 0 ; i < 5 ; i++) { |
546 |
table[i] = new Gtk::Table(3, 1); |
table[i] = new Gtk::Table(3, 1); |
547 |
table[i]->set_col_spacings(5); |
table[i]->set_col_spacings(5); |
791 |
m_Notebook.append_page(*table[2], "EG3"); |
m_Notebook.append_page(*table[2], "EG3"); |
792 |
m_Notebook.append_page(*table[3], "Velocity"); |
m_Notebook.append_page(*table[3], "Velocity"); |
793 |
m_Notebook.append_page(*table[4], "Misc"); |
m_Notebook.append_page(*table[4], "Misc"); |
794 |
m_Notebook.set_size_request(400, 500); |
// m_Notebook.set_size_request(400, 500); |
795 |
|
|
796 |
m_HPaned.add1(m_ScrolledWindow); |
m_TreeViewNotebook.set_size_request(300); |
797 |
|
m_HPaned.add1(m_TreeViewNotebook); |
798 |
m_HPaned.add2(m_Notebook); |
m_HPaned.add2(m_Notebook); |
799 |
|
|
800 |
|
|
801 |
m_TreeViewNotebook.append_page(m_TreeViewSamples, "Samples"); |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples"); |
802 |
m_TreeViewNotebook.append_page(m_TreeView, "Instruments"); |
m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments"); |
803 |
|
|
804 |
|
|
805 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
1285 |
|
|
1286 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
1287 |
{ |
{ |
1288 |
|
m_SampleImportQueue.clear(); |
1289 |
} |
} |
1290 |
|
|
1291 |
void MainWindow::on_action_file_open() |
void MainWindow::on_action_file_open() |
1308 |
} |
} |
1309 |
instrument_menu->get_submenu()->items().clear(); |
instrument_menu->get_submenu()->items().clear(); |
1310 |
|
|
1311 |
|
m_SampleImportQueue.clear(); |
1312 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
1313 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
1314 |
if (file) delete file; |
if (file) delete file; |
1348 |
|
|
1349 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1350 |
{ |
{ |
1351 |
|
if (!file) return; |
1352 |
|
file->Save(); |
1353 |
|
__import_queued_samples(); |
1354 |
} |
} |
1355 |
|
|
1356 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1357 |
{ |
{ |
1358 |
|
if (!file) return; |
1359 |
Gtk::FileChooserDialog dialog(*this, "Open", Gtk::FILE_CHOOSER_ACTION_SAVE); |
Gtk::FileChooserDialog dialog(*this, "Open", Gtk::FILE_CHOOSER_ACTION_SAVE); |
1360 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1361 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
1365 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1366 |
printf("filename=%s\n", dialog.get_filename().c_str()); |
printf("filename=%s\n", dialog.get_filename().c_str()); |
1367 |
file->Save(dialog.get_filename()); |
file->Save(dialog.get_filename()); |
1368 |
|
__import_queued_samples(); |
1369 |
|
} |
1370 |
|
} |
1371 |
|
|
1372 |
|
// actually write the sample(s)' data to the gig file |
1373 |
|
void MainWindow::__import_queued_samples() { |
1374 |
|
Glib::ustring error_files; |
1375 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) { |
1376 |
|
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1377 |
|
SF_INFO info; |
1378 |
|
info.format = 0; |
1379 |
|
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
1380 |
|
try { |
1381 |
|
if (!hFile) throw std::string("could not open file"); |
1382 |
|
// determine sample's bit depth |
1383 |
|
int bitdepth; |
1384 |
|
switch (info.format & 0xff) { |
1385 |
|
case SF_FORMAT_PCM_S8: |
1386 |
|
bitdepth = 16; // we simply convert to 16 bit for now |
1387 |
|
break; |
1388 |
|
case SF_FORMAT_PCM_16: |
1389 |
|
bitdepth = 16; |
1390 |
|
break; |
1391 |
|
case SF_FORMAT_PCM_24: |
1392 |
|
bitdepth = 32; // we simply convert to 32 bit for now |
1393 |
|
break; |
1394 |
|
case SF_FORMAT_PCM_32: |
1395 |
|
bitdepth = 32; |
1396 |
|
break; |
1397 |
|
case SF_FORMAT_PCM_U8: |
1398 |
|
bitdepth = 16; // we simply convert to 16 bit for now |
1399 |
|
break; |
1400 |
|
case SF_FORMAT_FLOAT: |
1401 |
|
bitdepth = 32; |
1402 |
|
break; |
1403 |
|
case SF_FORMAT_DOUBLE: |
1404 |
|
bitdepth = 32; // I guess we will always truncate this to 32 bit |
1405 |
|
break; |
1406 |
|
default: |
1407 |
|
sf_close(hFile); // close sound file |
1408 |
|
throw std::string("format not supported"); // unsupported subformat (yet?) |
1409 |
|
} |
1410 |
|
// allocate appropriate copy buffer (TODO: for now we copy it in one piece, might be tough for very long samples) |
1411 |
|
// and copy sample data into buffer |
1412 |
|
int8_t* buffer = NULL; |
1413 |
|
switch (bitdepth) { |
1414 |
|
case 16: |
1415 |
|
buffer = new int8_t[2 * info.channels * info.frames]; |
1416 |
|
sf_readf_short(hFile, (short*) buffer, info.frames); // libsndfile does the conversion for us (if needed) |
1417 |
|
break; |
1418 |
|
case 32: |
1419 |
|
buffer = new int8_t[4 * info.channels * info.frames]; |
1420 |
|
sf_readf_int(hFile, (int*) buffer, info.frames); // libsndfile does the conversion for us (if needed) |
1421 |
|
break; |
1422 |
|
} |
1423 |
|
// write from buffer directly (physically) into .gig file |
1424 |
|
(*iter).gig_sample->Write(buffer, info.frames); |
1425 |
|
// cleanup |
1426 |
|
sf_close(hFile); |
1427 |
|
delete buffer; |
1428 |
|
// on success we remove the sample from the import queue, otherwise keep it, maybe it works the next time ? |
1429 |
|
m_SampleImportQueue.erase(iter); |
1430 |
|
} catch (std::string what) { // remember the files that made trouble (and their cause) |
1431 |
|
if (error_files.size()) error_files += "\n"; |
1432 |
|
error_files += (*iter).sample_path += " (" + what + ")"; |
1433 |
|
} |
1434 |
|
} |
1435 |
|
// show error message box when some sample(s) could not be imported |
1436 |
|
if (error_files.size()) { |
1437 |
|
Glib::ustring txt = "Could not import the following sample(s):\n" + error_files; |
1438 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1439 |
|
msg.run(); |
1440 |
} |
} |
1441 |
} |
} |
1442 |
|
|
1644 |
instrument_menu->get_submenu()->show_all_children(); |
instrument_menu->get_submenu()->show_all_children(); |
1645 |
|
|
1646 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1647 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
if (group->Name != "") { |
1648 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1649 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1650 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
1651 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_group] = group; |
1652 |
for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) { |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1653 |
Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children()); |
for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) { |
1654 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children()); |
1655 |
rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); |
Gtk::TreeModel::Row rowSample = *iterSample; |
1656 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); |
1657 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1658 |
|
rowSample[m_SamplesModel.m_col_group] = NULL; |
1659 |
|
} |
1660 |
} |
} |
1661 |
} |
} |
1662 |
} |
} |
1771 |
int bitdepth; |
int bitdepth; |
1772 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
1773 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
1774 |
bitdepth = 8; |
bitdepth = 16; // we simply convert to 16 bit for now |
1775 |
break; |
break; |
1776 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
1777 |
bitdepth = 16; |
bitdepth = 16; |
1778 |
break; |
break; |
1779 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
1780 |
bitdepth = 24; |
bitdepth = 32; // we simply convert to 32 bit for now |
1781 |
break; |
break; |
1782 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
1783 |
bitdepth = 32; |
bitdepth = 32; |
1784 |
break; |
break; |
1785 |
|
case SF_FORMAT_PCM_U8: |
1786 |
|
bitdepth = 16; // we simply convert to 16 bit for now |
1787 |
|
break; |
1788 |
|
case SF_FORMAT_FLOAT: |
1789 |
|
bitdepth = 32; |
1790 |
|
break; |
1791 |
|
case SF_FORMAT_DOUBLE: |
1792 |
|
bitdepth = 32; // I guess we will always truncate this to 32 bit |
1793 |
|
break; |
1794 |
default: |
default: |
1795 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
1796 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string("format not supported"); // unsupported subformat (yet?) |
1797 |
} |
} |
1798 |
// add a new sample to the .gig file |
// add a new sample to the .gig file |
1799 |
gig::Sample* sample = file->AddSample(); |
gig::Sample* sample = file->AddSample(); |
1800 |
sample->pInfo->Name = (*iter).raw(); |
sample->pInfo->Name = (*iter).substr((*iter).rfind('/') + 1).raw(); // file name without path |
1801 |
sample->Channels = info.channels; |
sample->Channels = info.channels; |
1802 |
sample->BitDepth = bitdepth; |
sample->BitDepth = bitdepth; |
1803 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
1804 |
sample->SamplesPerSecond = info.samplerate; |
sample->SamplesPerSecond = info.samplerate; |
1805 |
// schedule resizing the sample (which will be done physically when File::Save() is called) |
// schedule resizing the sample (which will be done physically when File::Save() is called) |
1806 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
1807 |
|
// schedule that physical resize and sample import (data copying), performed when "Save" is requested |
1808 |
|
SampleImportItem sched_item; |
1809 |
|
sched_item.gig_sample = sample; |
1810 |
|
sched_item.sample_path = *iter; |
1811 |
|
m_SampleImportQueue.push_back(sched_item); |
1812 |
// add sample to the tree view |
// add sample to the tree view |
1813 |
Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(row.children()); |
Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(row.children()); |
1814 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
1846 |
} else if (sample) { |
} else if (sample) { |
1847 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
1848 |
} |
} |
1849 |
|
// if sample was just previously added, remove it from the import queue |
1850 |
|
if (sample) { |
1851 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) { |
1852 |
|
if ((*iter).gig_sample == sample) { |
1853 |
|
m_SampleImportQueue.erase(iter); |
1854 |
|
break; |
1855 |
|
} |
1856 |
|
} |
1857 |
|
} |
1858 |
// remove respective row(s) from samples tree view |
// remove respective row(s) from samples tree view |
1859 |
m_refSamplesTreeModel->erase(it); |
m_refSamplesTreeModel->erase(it); |
1860 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |