1372 |
// actually write the sample(s)' data to the gig file |
// actually write the sample(s)' data to the gig file |
1373 |
void MainWindow::__import_queued_samples() { |
void MainWindow::__import_queued_samples() { |
1374 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1375 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) { |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ) { |
1376 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1377 |
SF_INFO info; |
SF_INFO info; |
1378 |
info.format = 0; |
info.format = 0; |
1426 |
sf_close(hFile); |
sf_close(hFile); |
1427 |
delete buffer; |
delete buffer; |
1428 |
// on success we remove the sample from the import queue, otherwise keep it, maybe it works the next time ? |
// on success we remove the sample from the import queue, otherwise keep it, maybe it works the next time ? |
1429 |
m_SampleImportQueue.erase(iter); |
std::list<SampleImportItem>::iterator cur = iter; |
1430 |
|
++iter; |
1431 |
|
m_SampleImportQueue.erase(cur); |
1432 |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
1433 |
if (error_files.size()) error_files += "\n"; |
if (error_files.size()) error_files += "\n"; |
1434 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += (*iter).sample_path += " (" + what + ")"; |
1435 |
|
++iter; |
1436 |
} |
} |
1437 |
} |
} |
1438 |
// show error message box when some sample(s) could not be imported |
// show error message box when some sample(s) could not be imported |
1752 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1753 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
1754 |
dialog.set_select_multiple(true); |
dialog.set_select_multiple(true); |
1755 |
Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile (yet to do ;-) |
Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile |
1756 |
soundfilter.add_pattern("*.wav"); |
const char* supportedFileTypes[] = { |
1757 |
|
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
1758 |
|
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
1759 |
|
"*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64", |
1760 |
|
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
1761 |
|
"*.caf", "*.CAF", NULL |
1762 |
|
}; |
1763 |
|
for (int i = 0; supportedFileTypes[i]; i++) |
1764 |
|
soundfilter.add_pattern(supportedFileTypes[i]); |
1765 |
soundfilter.set_name("Sound Files"); |
soundfilter.set_name("Sound Files"); |
1766 |
Gtk::FileFilter allpassfilter; // matches every file |
Gtk::FileFilter allpassfilter; // matches every file |
1767 |
allpassfilter.add_pattern("*.*"); |
allpassfilter.add_pattern("*.*"); |
1815 |
sample->SamplesPerSecond = info.samplerate; |
sample->SamplesPerSecond = info.samplerate; |
1816 |
// 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) |
1817 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
1818 |
|
// make sure sample is part of the selected group |
1819 |
|
group->AddSample(sample); |
1820 |
// schedule that physical resize and sample import (data copying), performed when "Save" is requested |
// schedule that physical resize and sample import (data copying), performed when "Save" is requested |
1821 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
1822 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
1852 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
1853 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
1854 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
1855 |
|
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
1856 |
try { |
try { |
1857 |
// remove group or sample from the gig file |
// remove group or sample from the gig file |
1858 |
if (group) { |
if (group) { |
1859 |
|
// temporarily remember the samples that bolong to that group (we need that to clean the queue) |
1860 |
|
std::list<gig::Sample*> members; |
1861 |
|
for (gig::Sample* pSample = group->GetFirstSample(); pSample; pSample = group->GetNextSample()) { |
1862 |
|
members.push_back(pSample); |
1863 |
|
} |
1864 |
|
// delete the group in the .gig file including the samples that belong to the group |
1865 |
file->DeleteGroup(group); |
file->DeleteGroup(group); |
1866 |
|
// if sample(s) were just previously added, remove them from the import queue |
1867 |
|
for (std::list<gig::Sample*>::iterator member = members.begin(); member != members.end(); ++member) { |
1868 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) { |
1869 |
|
if ((*iter).gig_sample == *member) { |
1870 |
|
printf("Removing previously added sample '%s' from group '%s'\n", (*iter).sample_path.c_str(), name.c_str()); |
1871 |
|
m_SampleImportQueue.erase(iter); |
1872 |
|
break; |
1873 |
|
} |
1874 |
|
} |
1875 |
|
} |
1876 |
} else if (sample) { |
} else if (sample) { |
1877 |
|
// remove sample from the .gig file |
1878 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
1879 |
} |
// if sample was just previously added, remove it from the import queue |
|
// if sample was just previously added, remove it from the import queue |
|
|
if (sample) { |
|
1880 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) { |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ++iter) { |
1881 |
if ((*iter).gig_sample == sample) { |
if ((*iter).gig_sample == sample) { |
1882 |
|
printf("Removing previously added sample '%s'\n", (*iter).sample_path.c_str()); |
1883 |
m_SampleImportQueue.erase(iter); |
m_SampleImportQueue.erase(iter); |
1884 |
break; |
break; |
1885 |
} |
} |