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.")); |
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() |
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" + |
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 |
} |
} |
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) { |