38 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
39 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
40 |
#include <gtkmm/toggleaction.h> |
#include <gtkmm/toggleaction.h> |
41 |
|
#include <gtkmm/accelmap.h> |
42 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
43 |
#include "wrapLabel.hh" |
#include "wrapLabel.hh" |
44 |
#endif |
#endif |
59 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
60 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
61 |
#include "gfx/builtinpix.h" |
#include "gfx/builtinpix.h" |
62 |
|
#include "MacroEditor.h" |
63 |
|
#include "MacrosSetup.h" |
64 |
|
|
65 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
66 |
m_DimRegionChooser(*this), |
m_DimRegionChooser(*this), |
201 |
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
202 |
); |
); |
203 |
actionGroup->add( |
actionGroup->add( |
204 |
Gtk::Action::create("MenuScript", _("S_cript")), |
Gtk::Action::create("MenuScript", _("Scr_ipt")), |
205 |
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
206 |
); |
); |
207 |
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
208 |
|
|
209 |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
210 |
|
|
211 |
|
const Gdk::ModifierType primaryModifierKey = |
212 |
|
#if defined(__APPLE__) |
213 |
|
Gdk::META_MASK; // Cmd key on Mac |
214 |
|
#else |
215 |
|
Gdk::CONTROL_MASK; // Ctrl key on all other OSs |
216 |
|
#endif |
217 |
|
|
218 |
|
actionGroup->add(Gtk::Action::create("CopyDimRgn", |
219 |
|
_("Copy selected dimension region")), |
220 |
|
Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK), |
221 |
|
sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)); |
222 |
|
|
223 |
|
actionGroup->add(Gtk::Action::create("PasteDimRgn", |
224 |
|
_("Paste dimension region")), |
225 |
|
Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK), |
226 |
|
sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)); |
227 |
|
|
228 |
|
actionGroup->add(Gtk::Action::create("AdjustClipboard", |
229 |
|
_("Adjust Clipboard Content")), |
230 |
|
Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK), |
231 |
|
sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)); |
232 |
|
|
233 |
|
actionGroup->add(Gtk::Action::create("SelectPrevRegion", |
234 |
|
_("Select Previous Region")), |
235 |
|
Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey), |
236 |
|
sigc::mem_fun(*this, &MainWindow::select_prev_region)); |
237 |
|
|
238 |
|
actionGroup->add(Gtk::Action::create("SelectNextRegion", |
239 |
|
_("Select Next Region")), |
240 |
|
Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey), |
241 |
|
sigc::mem_fun(*this, &MainWindow::select_next_region)); |
242 |
|
|
243 |
|
actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone", |
244 |
|
_("Select Previous Dimension Region Zone")), |
245 |
|
Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK), |
246 |
|
sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)); |
247 |
|
|
248 |
|
actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone", |
249 |
|
_("Select Next Dimension Region Zone")), |
250 |
|
Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK), |
251 |
|
sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)); |
252 |
|
|
253 |
|
actionGroup->add(Gtk::Action::create("SelectPrevDimension", |
254 |
|
_("Select Previous Dimension")), |
255 |
|
Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK), |
256 |
|
sigc::mem_fun(*this, &MainWindow::select_prev_dimension)); |
257 |
|
|
258 |
|
actionGroup->add(Gtk::Action::create("SelectNextDimension", |
259 |
|
_("Select Next Dimension")), |
260 |
|
Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK), |
261 |
|
sigc::mem_fun(*this, &MainWindow::select_next_dimension)); |
262 |
|
|
263 |
|
actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone", |
264 |
|
_("Add Previous Dimension Region Zone to Selection")), |
265 |
|
Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK), |
266 |
|
sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)); |
267 |
|
|
268 |
|
actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone", |
269 |
|
_("Add Next Dimension Region Zone to Selection")), |
270 |
|
Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK), |
271 |
|
sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)); |
272 |
|
|
273 |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
274 |
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
275 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
286 |
actionGroup->add(toggle_action); |
actionGroup->add(toggle_action); |
287 |
|
|
288 |
|
|
289 |
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro"))); |
290 |
|
|
291 |
|
|
292 |
|
actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w"))); |
293 |
toggle_action = |
toggle_action = |
294 |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
295 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
447 |
" <menuitem action='Quit'/>" |
" <menuitem action='Quit'/>" |
448 |
" </menu>" |
" </menu>" |
449 |
" <menu action='MenuEdit'>" |
" <menu action='MenuEdit'>" |
450 |
|
" <menuitem action='CopyDimRgn'/>" |
451 |
|
" <menuitem action='AdjustClipboard'/>" |
452 |
|
" <menuitem action='PasteDimRgn'/>" |
453 |
|
" <separator/>" |
454 |
|
" <menuitem action='SelectPrevRegion'/>" |
455 |
|
" <menuitem action='SelectNextRegion'/>" |
456 |
|
" <separator/>" |
457 |
|
" <menuitem action='SelectPrevDimension'/>" |
458 |
|
" <menuitem action='SelectNextDimension'/>" |
459 |
|
" <menuitem action='SelectPrevDimRgnZone'/>" |
460 |
|
" <menuitem action='SelectNextDimRgnZone'/>" |
461 |
|
" <menuitem action='SelectAddPrevDimRgnZone'/>" |
462 |
|
" <menuitem action='SelectAddNextDimRgnZone'/>" |
463 |
|
" <separator/>" |
464 |
" <menuitem action='CopySampleUnity'/>" |
" <menuitem action='CopySampleUnity'/>" |
465 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
466 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
467 |
" </menu>" |
" </menu>" |
468 |
|
" <menu action='MenuMacro'>" |
469 |
|
" </menu>" |
470 |
" <menu action='MenuSample'>" |
" <menu action='MenuSample'>" |
471 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
472 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
825 |
|
|
826 |
// select 'Instruments' tab by default |
// select 'Instruments' tab by default |
827 |
// (gtk allows this only if the tab childs are visible, thats why it's here) |
// (gtk allows this only if the tab childs are visible, thats why it's here) |
828 |
m_TreeViewNotebook.set_current_page(1); |
m_TreeViewNotebook.set_current_page(1); |
829 |
|
|
830 |
|
Gtk::Clipboard::get()->signal_owner_change().connect( |
831 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change) |
832 |
|
); |
833 |
|
updateClipboardPasteAvailable(); |
834 |
|
updateClipboardCopyAvailable(); |
835 |
|
|
836 |
|
// setup macros and their keyboard accelerators |
837 |
|
{ |
838 |
|
Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>( |
839 |
|
uiManager->get_widget("/MenuBar/MenuMacro") |
840 |
|
)->get_submenu(); |
841 |
|
|
842 |
|
const Gdk::ModifierType primaryModifierKey = |
843 |
|
#if defined(__APPLE__) |
844 |
|
Gdk::META_MASK; // Cmd key on Mac |
845 |
|
#else |
846 |
|
Gdk::CONTROL_MASK; // Ctrl key on all other OSs |
847 |
|
#endif |
848 |
|
|
849 |
|
const Gdk::ModifierType noModifier = (Gdk::ModifierType)0; |
850 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier); |
851 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier); |
852 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier); |
853 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier); |
854 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier); |
855 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier); |
856 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier); |
857 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier); |
858 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier); |
859 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier); |
860 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier); |
861 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier); |
862 |
|
Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey); |
863 |
|
|
864 |
|
Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group(); |
865 |
|
menuMacro->set_accel_group(accelGroup); |
866 |
|
|
867 |
|
updateMacroMenu(); |
868 |
|
} |
869 |
} |
} |
870 |
|
|
871 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
872 |
{ |
{ |
873 |
} |
} |
874 |
|
|
875 |
|
void MainWindow::updateMacroMenu() { |
876 |
|
Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>( |
877 |
|
uiManager->get_widget("/MenuBar/MenuMacro") |
878 |
|
)->get_submenu(); |
879 |
|
|
880 |
|
// remove all entries from "Macro" menu |
881 |
|
{ |
882 |
|
const std::vector<Gtk::Widget*> children = menuMacro->get_children(); |
883 |
|
for (int i = 0; i < children.size(); ++i) { |
884 |
|
Gtk::Widget* child = children[i]; |
885 |
|
menuMacro->remove(*child); |
886 |
|
delete child; |
887 |
|
} |
888 |
|
} |
889 |
|
|
890 |
|
// (re)load all macros from config file |
891 |
|
try { |
892 |
|
Settings::singleton()->loadMacros(m_macros); |
893 |
|
} catch (Serialization::Exception e) { |
894 |
|
std::cerr << "Exception while loading macros: " << e.Message << std::endl; |
895 |
|
} catch (...) { |
896 |
|
std::cerr << "Unknown exception while loading macros!" << std::endl; |
897 |
|
} |
898 |
|
|
899 |
|
// add all configured macros as menu items to the "Macro" menu |
900 |
|
for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) { |
901 |
|
const Serialization::Archive& macro = m_macros[iMacro]; |
902 |
|
std::string name = |
903 |
|
macro.name().empty() ? |
904 |
|
(std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name(); |
905 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(name); |
906 |
|
item->signal_activate().connect( |
907 |
|
sigc::bind( |
908 |
|
sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro |
909 |
|
) |
910 |
|
); |
911 |
|
menuMacro->append(*item); |
912 |
|
item->set_accel_path("<Macros>/macro_" + ToString(iMacro)); |
913 |
|
} |
914 |
|
// if there are no macros configured at all, then show a dummy entry instead |
915 |
|
if (m_macros.empty()) { |
916 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros")); |
917 |
|
item->set_sensitive(false); |
918 |
|
menuMacro->append(*item); |
919 |
|
} |
920 |
|
|
921 |
|
// add separator line to menu |
922 |
|
menuMacro->append(*new Gtk::SeparatorMenuItem); |
923 |
|
|
924 |
|
{ |
925 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ...")); |
926 |
|
item->signal_activate().connect( |
927 |
|
sigc::mem_fun(*this, &MainWindow::setupMacros) |
928 |
|
); |
929 |
|
menuMacro->append(*item); |
930 |
|
item->set_accel_path("<Macros>/SetupMacros"); |
931 |
|
} |
932 |
|
|
933 |
|
menuMacro->show_all_children(); |
934 |
|
} |
935 |
|
|
936 |
|
void MainWindow::onMacroSelected(int iMacro) { |
937 |
|
printf("onMacroSelected(%d)\n", iMacro); |
938 |
|
if (iMacro < 0 || iMacro >= m_macros.size()) return; |
939 |
|
Glib::ustring errorText; |
940 |
|
try { |
941 |
|
applyMacro(m_macros[iMacro]); |
942 |
|
} catch (Serialization::Exception e) { |
943 |
|
errorText = e.Message; |
944 |
|
} catch (...) { |
945 |
|
errorText = _("Unknown exception while applying macro"); |
946 |
|
} |
947 |
|
if (!errorText.empty()) { |
948 |
|
Glib::ustring txt = _("Applying macro failed:\n") + errorText; |
949 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
950 |
|
msg.run(); |
951 |
|
} |
952 |
|
} |
953 |
|
|
954 |
|
void MainWindow::setupMacros() { |
955 |
|
MacrosSetup* setup = new MacrosSetup(); |
956 |
|
setup->setMacros(m_macros); |
957 |
|
setup->signal_macros_changed().connect( |
958 |
|
sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged) |
959 |
|
); |
960 |
|
setup->show(); |
961 |
|
} |
962 |
|
|
963 |
|
void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) { |
964 |
|
m_macros = macros; |
965 |
|
Settings::singleton()->saveMacros(m_macros); |
966 |
|
updateMacroMenu(); |
967 |
|
} |
968 |
|
|
969 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
bool MainWindow::on_delete_event(GdkEventAny* event) |
970 |
{ |
{ |
971 |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
1031 |
} |
} |
1032 |
} |
} |
1033 |
|
|
1034 |
|
m_RegionChooser.setModifyAllRegions(all_regions); |
1035 |
m_DimRegionChooser.setModifyAllRegions(all_regions); |
m_DimRegionChooser.setModifyAllRegions(all_regions); |
1036 |
m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs); |
m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs); |
1037 |
m_DimRegionChooser.setModifyBothChannels(stereo); |
m_DimRegionChooser.setModifyBothChannels(stereo); |
1038 |
|
|
1039 |
|
updateClipboardCopyAvailable(); |
1040 |
} |
} |
1041 |
|
|
1042 |
void MainWindow::dimreg_all_dimregs_toggled() |
void MainWindow::dimreg_all_dimregs_toggled() |
1669 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1670 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1671 |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1672 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1673 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1674 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",iter->second.sample_path.c_str()); |
1675 |
SF_INFO info; |
SF_INFO info; |
1676 |
info.format = 0; |
info.format = 0; |
1677 |
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); |
1678 |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
1679 |
try { |
try { |
1680 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
1697 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1698 |
} |
} |
1699 |
|
|
1700 |
|
// reset write position for sample |
1701 |
|
iter->first->SetPos(0); |
1702 |
|
|
1703 |
const int bufsize = 10000; |
const int bufsize = 10000; |
1704 |
switch (bitdepth) { |
switch (bitdepth) { |
1705 |
case 16: { |
case 16: { |
1709 |
// libsndfile does the conversion for us (if needed) |
// libsndfile does the conversion for us (if needed) |
1710 |
int n = sf_readf_short(hFile, buffer, bufsize); |
int n = sf_readf_short(hFile, buffer, bufsize); |
1711 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1712 |
iter->gig_sample->Write(buffer, n); |
iter->first->Write(buffer, n); |
1713 |
cnt -= n; |
cnt -= n; |
1714 |
} |
} |
1715 |
delete[] buffer; |
delete[] buffer; |
1729 |
dstbuf[j++] = srcbuf[i] >> 24; |
dstbuf[j++] = srcbuf[i] >> 24; |
1730 |
} |
} |
1731 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1732 |
iter->gig_sample->Write(dstbuf, n); |
iter->first->Write(dstbuf, n); |
1733 |
cnt -= n; |
cnt -= n; |
1734 |
} |
} |
1735 |
delete[] srcbuf; |
delete[] srcbuf; |
1740 |
// cleanup |
// cleanup |
1741 |
sf_close(hFile); |
sf_close(hFile); |
1742 |
// let the sampler re-cache the sample if needed |
// let the sampler re-cache the sample if needed |
1743 |
sample_changed_signal.emit(iter->gig_sample); |
sample_changed_signal.emit(iter->first); |
1744 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
1745 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
1746 |
std::list<SampleImportItem>::iterator cur = iter; |
std::map<gig::Sample*, SampleImportItem>::iterator cur = iter; |
1747 |
++iter; |
++iter; |
1748 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
1749 |
} catch (std::string what) { |
} catch (std::string what) { |
1750 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
1751 |
if (!error_files.empty()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1752 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += iter->second.sample_path += " (" + what + ")"; |
1753 |
++iter; |
++iter; |
1754 |
} |
} |
1755 |
} |
} |
2971 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2972 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
2973 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2974 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
2975 |
// add sample to the tree view |
// add sample to the tree view |
2976 |
if (replace) { |
if (replace) { |
2977 |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
3081 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
3082 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
3083 |
sched_item.sample_path = filename; |
sched_item.sample_path = filename; |
3084 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
3085 |
sf_close(hFile); |
sf_close(hFile); |
3086 |
file_changed(); |
file_changed(); |
3087 |
} |
} |
3133 |
// if sample(s) were just previously added, remove |
// if sample(s) were just previously added, remove |
3134 |
// them from the import queue |
// them from the import queue |
3135 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
3136 |
member != members.end(); ++member) { |
member != members.end(); ++member) |
3137 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
{ |
3138 |
iter != m_SampleImportQueue.end(); ++iter) { |
if (m_SampleImportQueue.count(*member)) { |
3139 |
if ((*iter).gig_sample == *member) { |
printf("Removing previously added sample '%s' from group '%s'\n", |
3140 |
printf("Removing previously added sample '%s' from group '%s'\n", |
m_SampleImportQueue[sample].sample_path.c_str(), name.c_str()); |
3141 |
(*iter).sample_path.c_str(), name.c_str()); |
m_SampleImportQueue.erase(*member); |
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
3142 |
} |
} |
3143 |
} |
} |
3144 |
file_changed(); |
file_changed(); |
3153 |
samples_removed_signal.emit(); |
samples_removed_signal.emit(); |
3154 |
// if sample was just previously added, remove it from |
// if sample was just previously added, remove it from |
3155 |
// the import queue |
// the import queue |
3156 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
3157 |
iter != m_SampleImportQueue.end(); ++iter) { |
printf("Removing previously added sample '%s'\n", |
3158 |
if ((*iter).gig_sample == sample) { |
m_SampleImportQueue[sample].sample_path.c_str()); |
3159 |
printf("Removing previously added sample '%s'\n", |
m_SampleImportQueue.erase(sample); |
|
(*iter).sample_path.c_str()); |
|
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
3160 |
} |
} |
3161 |
dimreg_changed(); |
dimreg_changed(); |
3162 |
file_changed(); |
file_changed(); |
3212 |
gig::Sample* sample = *itSample; |
gig::Sample* sample = *itSample; |
3213 |
// remove sample from the .gig file |
// remove sample from the .gig file |
3214 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
3215 |
// if sample was just previously added, remove it fro the import queue |
// if sample was just previously added, remove it from the import queue |
3216 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
3217 |
iter != m_SampleImportQueue.end(); ++iter) |
printf("Removing previously added sample '%s'\n", |
3218 |
{ |
m_SampleImportQueue[sample].sample_path.c_str()); |
3219 |
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; |
|
|
} |
|
3220 |
} |
} |
3221 |
} |
} |
3222 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
3792 |
m_TreeViewNotebook.set_current_page(2); |
m_TreeViewNotebook.set_current_page(2); |
3793 |
} |
} |
3794 |
|
|
3795 |
|
void MainWindow::select_prev_region() { |
3796 |
|
m_RegionChooser.select_prev_region(); |
3797 |
|
} |
3798 |
|
|
3799 |
|
void MainWindow::select_next_region() { |
3800 |
|
m_RegionChooser.select_next_region(); |
3801 |
|
} |
3802 |
|
|
3803 |
|
void MainWindow::select_next_dim_rgn_zone() { |
3804 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3805 |
|
m_DimRegionChooser.select_next_dimzone(); |
3806 |
|
} |
3807 |
|
|
3808 |
|
void MainWindow::select_prev_dim_rgn_zone() { |
3809 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3810 |
|
m_DimRegionChooser.select_prev_dimzone(); |
3811 |
|
} |
3812 |
|
|
3813 |
|
void MainWindow::select_add_next_dim_rgn_zone() { |
3814 |
|
m_DimRegionChooser.select_next_dimzone(true); |
3815 |
|
} |
3816 |
|
|
3817 |
|
void MainWindow::select_add_prev_dim_rgn_zone() { |
3818 |
|
m_DimRegionChooser.select_prev_dimzone(true); |
3819 |
|
} |
3820 |
|
|
3821 |
|
void MainWindow::select_prev_dimension() { |
3822 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3823 |
|
m_DimRegionChooser.select_prev_dimension(); |
3824 |
|
} |
3825 |
|
|
3826 |
|
void MainWindow::select_next_dimension() { |
3827 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3828 |
|
m_DimRegionChooser.select_next_dimension(); |
3829 |
|
} |
3830 |
|
|
3831 |
|
#define CLIPBOARD_DIMENSIONREGION_TARGET \ |
3832 |
|
("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat()) |
3833 |
|
|
3834 |
|
void MainWindow::copy_selected_dimrgn() { |
3835 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
3836 |
|
if (!pDimRgn) { |
3837 |
|
updateClipboardPasteAvailable(); |
3838 |
|
updateClipboardCopyAvailable(); |
3839 |
|
return; |
3840 |
|
} |
3841 |
|
|
3842 |
|
std::vector<Gtk::TargetEntry> targets; |
3843 |
|
targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) ); |
3844 |
|
|
3845 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
3846 |
|
clipboard->set( |
3847 |
|
targets, |
3848 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_get), |
3849 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_clear) |
3850 |
|
); |
3851 |
|
|
3852 |
|
m_serializationArchive.serialize(pDimRgn); |
3853 |
|
|
3854 |
|
updateClipboardPasteAvailable(); |
3855 |
|
} |
3856 |
|
|
3857 |
|
void MainWindow::paste_copied_dimrgn() { |
3858 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
3859 |
|
clipboard->request_contents( |
3860 |
|
CLIPBOARD_DIMENSIONREGION_TARGET, |
3861 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_received) |
3862 |
|
); |
3863 |
|
updateClipboardPasteAvailable(); |
3864 |
|
} |
3865 |
|
|
3866 |
|
void MainWindow::adjust_clipboard_content() { |
3867 |
|
MacroEditor* editor = new MacroEditor(); |
3868 |
|
editor->setMacro(&m_serializationArchive); |
3869 |
|
editor->show(); |
3870 |
|
} |
3871 |
|
|
3872 |
|
void MainWindow::updateClipboardPasteAvailable() { |
3873 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
3874 |
|
clipboard->request_targets( |
3875 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets) |
3876 |
|
); |
3877 |
|
} |
3878 |
|
|
3879 |
|
void MainWindow::updateClipboardCopyAvailable() { |
3880 |
|
bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion(); |
3881 |
|
static_cast<Gtk::MenuItem*>( |
3882 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn") |
3883 |
|
)->set_sensitive(bDimensionRegionCopyIsPossible); |
3884 |
|
} |
3885 |
|
|
3886 |
|
void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) { |
3887 |
|
updateClipboardPasteAvailable(); |
3888 |
|
} |
3889 |
|
|
3890 |
|
void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) { |
3891 |
|
const std::string target = selection_data.get_target(); |
3892 |
|
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
3893 |
|
selection_data.set( |
3894 |
|
CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/, |
3895 |
|
&m_serializationArchive.rawData()[0], |
3896 |
|
m_serializationArchive.rawData().size() |
3897 |
|
); |
3898 |
|
} else { |
3899 |
|
std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n"; |
3900 |
|
} |
3901 |
|
} |
3902 |
|
|
3903 |
|
void MainWindow::on_clipboard_clear() { |
3904 |
|
m_serializationArchive.clear(); |
3905 |
|
updateClipboardPasteAvailable(); |
3906 |
|
updateClipboardCopyAvailable(); |
3907 |
|
} |
3908 |
|
|
3909 |
|
//NOTE: Might throw exception !!! |
3910 |
|
void MainWindow::applyMacro(Serialization::Archive& macro) { |
3911 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
3912 |
|
if (!pDimRgn) return; |
3913 |
|
|
3914 |
|
for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin(); |
3915 |
|
itDimReg != dimreg_edit.dimregs.end(); ++itDimReg) |
3916 |
|
{ |
3917 |
|
gig::DimensionRegion* pDimRgn = *itDimReg; |
3918 |
|
dimreg_to_be_changed_signal.emit(pDimRgn); |
3919 |
|
m_serializationArchive.deserialize(pDimRgn); |
3920 |
|
dimreg_changed_signal.emit(pDimRgn); |
3921 |
|
} |
3922 |
|
//region_changed() |
3923 |
|
file_changed(); |
3924 |
|
dimreg_changed(); |
3925 |
|
} |
3926 |
|
|
3927 |
|
void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) { |
3928 |
|
const std::string target = selection_data.get_target(); |
3929 |
|
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
3930 |
|
Glib::ustring errorText; |
3931 |
|
try { |
3932 |
|
m_serializationArchive.decode( |
3933 |
|
selection_data.get_data(), selection_data.get_length() |
3934 |
|
); |
3935 |
|
applyMacro(m_serializationArchive); |
3936 |
|
} catch (Serialization::Exception e) { |
3937 |
|
errorText = e.Message; |
3938 |
|
} catch (...) { |
3939 |
|
errorText = _("Unknown exception while pasting DimensionRegion"); |
3940 |
|
} |
3941 |
|
if (!errorText.empty()) { |
3942 |
|
Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText; |
3943 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
3944 |
|
msg.run(); |
3945 |
|
} |
3946 |
|
} |
3947 |
|
} |
3948 |
|
|
3949 |
|
void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) { |
3950 |
|
const bool bDimensionRegionPasteIsPossible = |
3951 |
|
std::find(targets.begin(), targets.end(), |
3952 |
|
CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end(); |
3953 |
|
|
3954 |
|
static_cast<Gtk::MenuItem*>( |
3955 |
|
uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn") |
3956 |
|
)->set_sensitive(bDimensionRegionPasteIsPossible); |
3957 |
|
|
3958 |
|
static_cast<Gtk::MenuItem*>( |
3959 |
|
uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard") |
3960 |
|
)->set_sensitive(bDimensionRegionPasteIsPossible); |
3961 |
|
} |
3962 |
|
|
3963 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
3964 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
3965 |
} |
} |