2 * This file is part of ShapeFusion (Copyright 2000 Tito Dal Canton)
4 * ShapeFusion is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * ShapeFusion is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with ShapeFusion; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
30 #include "wx/wfstream.h"
32 #include "../ShapeFusionApp.h"
33 #include "../ShapeFusionMenus.h"
34 #include "../DefaultNames.h"
35 #include "SoundsView.h"
37 BEGIN_EVENT_TABLE(SoundsView, wxView)
38 EVT_LISTBOX(SOUND_CLASS_LIST, SoundsView::SoundClassChanged)
39 EVT_TEXT(SOUND_CLASS_ID_FIELD, SoundsView::SoundClassIdChanged)
40 EVT_RADIOBOX(SOUND_VOLUME_RADIO_BUTTON, SoundsView::VolumeButtonChanged)
41 EVT_CHOICE(SOUND_CHANCE_MENU, SoundsView::ChanceMenuChanged)
42 EVT_CHECKBOX(SOUND_FLAGS_RESTART, SoundsView::FlagsChanged)
43 EVT_CHECKBOX(SOUND_FLAGS_ABORT, SoundsView::FlagsChanged)
44 EVT_CHECKBOX(SOUND_FLAGS_RESIST, SoundsView::FlagsChanged)
45 EVT_CHECKBOX(SOUND_FLAGS_CHANGE, SoundsView::FlagsChanged)
46 EVT_CHECKBOX(SOUND_FLAGS_OBSTRUCTED, SoundsView::FlagsChanged)
47 EVT_CHECKBOX(SOUND_FLAGS_MOBSTRUCTED, SoundsView::FlagsChanged)
48 EVT_CHECKBOX(SOUND_FLAGS_AMBIENT, SoundsView::FlagsChanged)
49 EVT_LISTBOX(SOUND_EIGHT_BIT_PERMUTATIONS_LIST, SoundsView::SoundPermutationSelected)
50 EVT_LISTBOX(SOUND_SIXTEEN_BIT_PERMUTATIONS_LIST, SoundsView::SoundPermutationSelected)
51 EVT_LISTBOX_DCLICK(SOUND_EIGHT_BIT_PERMUTATIONS_LIST, SoundsView::SoundPermutationDoubleClicked)
52 EVT_LISTBOX_DCLICK(SOUND_SIXTEEN_BIT_PERMUTATIONS_LIST, SoundsView::SoundPermutationDoubleClicked)
53 EVT_MENU(EDIT_MENU_DELETE, SoundsView::MenuDelete)
54 EVT_MENU(SOUNDS_MENU_ADDCLASS, SoundsView::MenuAddSoundClass)
55 EVT_MENU(SOUNDS_MENU_EXPORT, SoundsView::MenuExportSound)
56 EVT_MENU(SOUNDS_MENU_IMPORT, SoundsView::MenuImportSound)
59 IMPLEMENT_DYNAMIC_CLASS(SoundsView, wxView)
61 SoundsView::SoundsView(): mSoundClass(wxNOT_FOUND), mSoundSource(wxNOT_FOUND), mSoundPermutation(wxNOT_FOUND)
68 // What to do when a view is created. Creates actual
69 // windows for displaying the view.
70 bool SoundsView::OnCreate(wxDocument *doc, long WXUNUSED(flags))
72 wxString frameTitle = _T("ShapeFusion : Sounds : ");
74 frameTitle.Append(doc->GetFilename());
76 frame = wxGetApp().CreateChildFrame(doc, this, frameTitle, wxPoint(0, 0), wxSize(600, 400), wxDEFAULT_FRAME_STYLE);// & ~ (wxRESIZE_BORDER | wxRESIZE_BOX | wxMAXIMIZE_BOX));
78 payload = (SoundsDocument*)doc;
80 menubar = frame->GetMenuBar();
81 CreateSoundsMenu(menubar);
83 // Because we can always add sound classes
84 menubar->Enable(SOUNDS_MENU_ADDCLASS, true);
86 wxString volume_labels[] = { wxT("Soft"), wxT("Medium"), wxT("Loud") };
87 wxString chances_labels[] = { wxT("100%"), wxT("90%"), wxT("80%"), wxT("70%"), wxT("60%"), wxT("50%"), wxT("40%"), wxT("30%"), wxT("20%"), wxT("10%") };
89 main_panel = new wxPanel(frame);
92 sound_class_text = new wxStaticText(main_panel, wxID_ANY, wxT("Sound classes: "));
93 sound_class_id_text = new wxStaticText(main_panel, wxID_ANY, wxT("Class ID: "));
94 sound_class_id_field = new wxTextCtrl(main_panel, SOUND_CLASS_ID_FIELD, wxT(""));
96 sound_class_number_text = new wxStaticText(main_panel, wxID_ANY, wxT("Class number: "));
97 sound_class_number_field = new wxStaticText(main_panel, SOUND_CLASS_NUMBER_FIELD, wxT(""));
99 sound_class_list = new wxListBox(main_panel, (wxWindowID)SOUND_CLASS_LIST);
101 sound_flag_restart_checkbox = new wxCheckBox(main_panel, SOUND_FLAGS_RESTART, wxT("Cannot be restarted"));
102 sound_flag_abort_checkbox = new wxCheckBox(main_panel, SOUND_FLAGS_ABORT, wxT("Does not self-abort"));
103 sound_flag_resist_checkbox = new wxCheckBox(main_panel, SOUND_FLAGS_RESIST, wxT("Resists pitch changes"));
104 sound_flag_change_checkbox = new wxCheckBox(main_panel, SOUND_FLAGS_CHANGE, wxT("Can't change pitch"));
105 sound_flag_obstructed_checkbox = new wxCheckBox(main_panel, SOUND_FLAGS_OBSTRUCTED, wxT("Can't be obstructed"));
106 sound_flag_mobstructed_checkbox = new wxCheckBox(main_panel, SOUND_FLAGS_MOBSTRUCTED, wxT("Can't be media obstructed"));
107 sound_flag_ambient_checkbox = new wxCheckBox(main_panel, SOUND_FLAGS_AMBIENT, wxT("Is ambient"));
109 sound_volume_radio_button = new wxRadioBox(main_panel, SOUND_VOLUME_RADIO_BUTTON, wxT("Volume"), wxDefaultPosition, wxDefaultSize, 3, volume_labels, 3, wxRA_SPECIFY_COLS);
111 sound_chance_text = new wxStaticText(main_panel, wxID_ANY, wxT("Chance: "));
112 sound_chance_menu = new wxChoice(main_panel, SOUND_CHANCE_MENU, wxDefaultPosition, wxDefaultSize, 10, chances_labels);
114 sound_low_pitch_text = new wxStaticText(main_panel, wxID_ANY, wxT("Low pitch: "));
115 sound_low_pitch_field = new wxTextCtrl(main_panel, SOUND_LOW_PITCH_FIELD);
116 sound_high_pitch_text = new wxStaticText(main_panel, wxID_ANY, wxT("High pitch: "));
117 sound_high_pitch_field = new wxTextCtrl(main_panel, SOUND_HIGH_PITCH_FIELD);
119 sound_eight_bit_text = new wxStaticText(main_panel, wxID_ANY, wxT("8-bit sounds:"));
120 sound_eight_bit_list = new wxListBox(main_panel, (wxWindowID)SOUND_EIGHT_BIT_PERMUTATIONS_LIST);
122 sound_sixteen_bit_text = new wxStaticText(main_panel, wxID_ANY, wxT("16-bit sounds: "));
123 sound_sixteen_bit_list = new wxListBox(main_panel, (wxWindowID)SOUND_SIXTEEN_BIT_PERMUTATIONS_LIST);
125 sound_remap_check_box = new wxCheckBox(main_panel, SOUND_REMAP_CHECK_BOX, wxT("Remap 8-bit"));
127 frame_sizer = new wxBoxSizer(wxHORIZONTAL);
128 sound_class_sizer = new wxBoxSizer(wxVERTICAL);
129 sound_class_header_sizer = new wxFlexGridSizer(2, 2, 0, 0);
130 sound_editor_sizer = new wxBoxSizer(wxVERTICAL);
131 sound_flags_sizer = new wxStaticBoxSizer(wxVERTICAL, main_panel, wxT("Flags"));
132 sound_menus_sizer = new wxFlexGridSizer(2, 3, 0, 0);
133 sound_permutation_sizer = new wxBoxSizer(wxHORIZONTAL);
134 sound_eight_bit_sizer = new wxBoxSizer(wxVERTICAL);
135 sound_sixteen_bit_sizer = new wxBoxSizer(wxVERTICAL);
137 sound_class_header_sizer->Add(sound_class_id_text, 0, wxALIGN_CENTER_VERTICAL, 0);
138 sound_class_header_sizer->Add(sound_class_id_field, 0, 0, 0);
139 sound_class_header_sizer->Add(sound_class_number_text, 0, wxALIGN_CENTER_VERTICAL, 0);
140 sound_class_header_sizer->Add(sound_class_number_field, 0, 0, 0);
142 sound_class_sizer->Add(sound_class_text, 0, 0, 0);
143 sound_class_sizer->Add(sound_class_header_sizer, 0, 0, 0);
144 sound_class_sizer->Add(sound_class_list, 1, wxEXPAND, 0);
146 sound_flags_sizer->Add(sound_flag_restart_checkbox, 0, 0, 0);
147 sound_flags_sizer->Add(sound_flag_abort_checkbox, 0, 0, 0);
148 sound_flags_sizer->Add(sound_flag_resist_checkbox, 0, 0, 0);
149 sound_flags_sizer->Add(sound_flag_change_checkbox, 0, 0, 0);
150 sound_flags_sizer->Add(sound_flag_obstructed_checkbox, 0, 0, 0);
151 sound_flags_sizer->Add(sound_flag_mobstructed_checkbox, 0, 0, 0);
152 sound_flags_sizer->Add(sound_flag_ambient_checkbox, 0, 0, 0);
154 sound_menus_sizer->Add(sound_chance_text, 0, wxALIGN_CENTER_VERTICAL, 0);
155 sound_menus_sizer->Add(sound_chance_menu, 0, 0, 0);
156 sound_menus_sizer->Add(sound_low_pitch_text, 0, wxALIGN_CENTER_VERTICAL, 0);
157 sound_menus_sizer->Add(sound_low_pitch_field, 0, 0, 0);
158 sound_menus_sizer->Add(sound_high_pitch_text, 0, wxALIGN_CENTER_VERTICAL, 0);
159 sound_menus_sizer->Add(sound_high_pitch_field, 0, 0, 0);
161 sound_eight_bit_sizer->Add(sound_eight_bit_text, 0, 0, 0);
162 sound_eight_bit_sizer->Add(sound_eight_bit_list, 1, wxEXPAND | wxRIGHT, 5);
163 sound_sixteen_bit_sizer->Add(sound_sixteen_bit_text, 0, 0, 0);
164 sound_sixteen_bit_sizer->Add(sound_sixteen_bit_list, 1, wxEXPAND, 0);
165 sound_sixteen_bit_sizer->Add(sound_remap_check_box, 0, 0, 0);
167 sound_permutation_sizer->Add(sound_eight_bit_sizer, 1, wxEXPAND, 0);
168 sound_permutation_sizer->Add(sound_sixteen_bit_sizer, 1, wxEXPAND, 0);
170 sound_editor_sizer->Add(sound_flags_sizer, 0, 0, 0);
171 sound_editor_sizer->AddSpacer(1);
172 sound_editor_sizer->Add(sound_volume_radio_button, 0, 0, 0);
173 sound_editor_sizer->AddSpacer(1);
174 sound_editor_sizer->Add(sound_menus_sizer, 0, 0, 0);
175 sound_editor_sizer->AddSpacer(5);
176 sound_editor_sizer->Add(sound_permutation_sizer, 1, wxEXPAND, 0);
178 frame_sizer->Add(sound_class_sizer, 0, wxEXPAND | wxALL, 5);
179 frame_sizer->AddSpacer(5);
180 frame_sizer->Add(sound_editor_sizer, 0, wxEXPAND | wxALL, 5);
182 main_panel->SetSizer(frame_sizer);
183 frame_sizer->Layout();
184 frame_sizer->SetSizeHints(frame);
188 // X seems to require a forced resize
190 frame->GetSize(&x, &y);
191 frame->SetSize(wxDefaultCoord, wxDefaultCoord, x, y);
197 // Sneakily gets used for default print/preview
198 // as well as drawing on the screen.
199 void SoundsView::OnDraw(wxDC *dc)
203 void SoundsView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint))
207 sound_class_list->Clear();
208 for (unsigned int i = 0; i < payload->GetSoundCount(); i++) {
209 sound_class_list->Append(GetName(wxT("sound"), i));
210 // We check if there is a difference between 8-bit and 16-bit
212 SoundsDefinition *def8 = payload->Get8BitSoundDefinition(i),
213 *def16 = payload->Get16BitSoundDefinition(i);
216 if (def8 != NULL && def16 != NULL)
217 equals = def8->HaveSameAttributesAs(*def16);
218 else if (def8 == NULL && def16 == NULL)
222 wxLogDebug(wxT("Sound source different at %d"), i);
223 gequals = gequals && equals;
226 // FIXME : Update this when we have a "complete" editor...
227 wxMessageDialog msg(frame,
228 wxT("It seems 8-bit and 16-bit versions of some of this Sound file "
229 "sounds have differences. This editor will replace 16-bit sounds "
230 "flags with those from 8-bit sounds, to ensure consistency. "
231 "If you really need to be able to change 16-bit flags independently, "
232 "please file a feature request."),
233 wxT("Warning !"), wxOK | wxICON_WARNING);
240 void SoundsView::Update(void)
242 // We disable our menuitems, in case selection is invalid
243 menubar->Enable(SOUNDS_MENU_IMPORT, false);
244 menubar->Enable(SOUNDS_MENU_EXPORT, false);
245 menubar->Enable(EDIT_MENU_DELETE, false);
247 if (sound_class_list->GetCount() == 0) {
248 // There is no sound class
249 // We cannot have a selection
250 mSoundPermutation = wxNOT_FOUND;
251 mSoundSource = wxNOT_FOUND;
254 // We have a sound class
256 // Make sure we always have something selected
257 mSoundClass = sound_class_list->GetSelection();
258 if (mSoundClass == wxNOT_FOUND) {
259 wxLogDebug(wxT("[SoundsView] There is no sound selected. Selecting first item..."));
260 sound_class_list->SetSelection(0);
261 mSoundClass = sound_class_list->GetSelection();
264 // We build the permutations listbox
265 sound_eight_bit_list->Clear();
266 sound_sixteen_bit_list->Clear();
268 SoundsDefinition *def = payload->Get8BitSoundDefinition(mSoundClass);
270 for (unsigned int i = 0; i < def->GetPermutationCount(); i++) {
271 sound_eight_bit_list->Append(wxString::Format(wxT("%d"), def->GetPermutation(i)->Size()));
275 def = payload->Get16BitSoundDefinition(mSoundClass);
277 for (unsigned int i = 0; i < def->GetPermutationCount(); i++) {
278 sound_sixteen_bit_list->Append(wxString::Format(wxT("%d"), def->GetPermutation(i)->Size()));
282 // As soon as we have a sound class selected, we can
283 // - import a sound into it
285 menubar->Enable(SOUNDS_MENU_IMPORT, true);
286 menubar->Enable(EDIT_MENU_DELETE, true);
288 if (payload->Get8BitSoundDefinition(mSoundClass)->GetPermutationCount() != 0) {
289 // There is 8-bit sounds, we select first
291 mSoundPermutation = 0;
292 sound_eight_bit_list->SetSelection(0);
293 // We deselect 16-bit list
294 sound_sixteen_bit_list->SetSelection(wxNOT_FOUND);
296 // There is no 8-bit sounds
297 if (payload->Get16BitSoundDefinition(mSoundClass)->GetPermutationCount() != 0) {
298 // We have 16-bit sounds, we select this one...
300 mSoundPermutation = 0;
301 sound_sixteen_bit_list->SetSelection(0);
302 // We deselect 8-bit list
303 sound_eight_bit_list->SetSelection(wxNOT_FOUND);
305 // There is neither 8-bit nor 16-bit sounds, don't select anything
306 sound_eight_bit_list->SetSelection(wxNOT_FOUND);
307 sound_sixteen_bit_list->SetSelection(wxNOT_FOUND);
308 mSoundSource = wxNOT_FOUND;
309 mSoundPermutation = wxNOT_FOUND;
313 // We enable this, our selection is valid...
314 menubar->Enable(SOUNDS_MENU_EXPORT, true);
316 def = payload->Get8BitSoundDefinition(mSoundClass);
318 sound_class_number_field->SetLabel(wxString::Format(wxT("%d"), mSoundClass));
319 sound_class_id_field->ChangeValue(wxString::Format(wxT("%d"), def->GetSoundCode()));
321 sound_volume_radio_button->SetSelection(def->GetBehaviorIndex());
322 sound_chance_menu->SetSelection(def->GetChance());
324 sound_flag_restart_checkbox->SetValue(def->IsNotRestartable());
325 sound_flag_abort_checkbox->SetValue(def->IsNotSelfAbortable());
326 sound_flag_resist_checkbox->SetValue(def->IsPitchChangeResistant());
327 sound_flag_change_checkbox->SetValue(def->IsNotPitchChangeable());
328 sound_flag_obstructed_checkbox->SetValue(def->IsNotObstructed());
329 sound_flag_mobstructed_checkbox->SetValue(def->IsNotMediaObstructed());
330 sound_flag_ambient_checkbox->SetValue(def->IsAmbient());
331 sound_low_pitch_field->ChangeValue(wxString::Format(wxT("%g"), def->GetLowPitch()));
332 sound_high_pitch_field->ChangeValue(wxString::Format(wxT("%g"), def->GetHighPitch()));
336 // Clean up windows used for displaying the view.
337 bool SoundsView::OnClose(bool deleteWindow)
339 if (!GetDocument()->Close())
341 SetFrame((wxFrame *) NULL);
350 void SoundsView::SoundClassChanged(wxCommandEvent &e)
355 void SoundsView::SoundClassIdChanged(wxCommandEvent& e)
358 if (e.GetString().ToLong(&v))
360 SoundsDefinition* def = payload->Get8BitSoundDefinition(mSoundClass);
361 def->SetSoundCode(v);
363 def = payload->Get16BitSoundDefinition(mSoundClass);
364 def->SetSoundCode(v);
366 GetDocument()->Modify(true);
369 void SoundsView::VolumeButtonChanged(wxCommandEvent &e)
371 SoundsDefinition *def = payload->Get8BitSoundDefinition(mSoundClass);
372 def->SetBehaviorIndex(sound_volume_radio_button->GetSelection());
374 def = payload->Get16BitSoundDefinition(mSoundClass);
375 def->SetBehaviorIndex(sound_volume_radio_button->GetSelection());
376 GetDocument()->Modify(true);
379 void SoundsView::ChanceMenuChanged(wxCommandEvent &e)
381 SoundsDefinition *def = payload->Get8BitSoundDefinition(mSoundClass);
382 def->SetChance(sound_chance_menu->GetSelection());
384 def = payload->Get16BitSoundDefinition(mSoundClass);
385 def->SetChance(sound_chance_menu->GetSelection());
386 GetDocument()->Modify(true);
389 void SoundsView::FlagsChanged(wxCommandEvent &e)
391 SoundsDefinition *def8 = payload->Get8BitSoundDefinition(mSoundClass);
392 SoundsDefinition *def16 = payload->Get16BitSoundDefinition(mSoundClass);
394 case SOUND_FLAGS_RESTART:
395 def8->SetNotRestartable(e.IsChecked());
396 def16->SetNotRestartable(e.IsChecked());
398 case SOUND_FLAGS_ABORT:
399 def8->SetNotSelfAbortable(e.IsChecked());
400 def16->SetNotSelfAbortable(e.IsChecked());
402 case SOUND_FLAGS_RESIST:
403 def8->SetPitchChangeResistant(e.IsChecked());
404 def16->SetPitchChangeResistant(e.IsChecked());
406 case SOUND_FLAGS_CHANGE:
407 def8->SetNotPitchChangeable(e.IsChecked());
408 def16->SetNotPitchChangeable(e.IsChecked());
410 case SOUND_FLAGS_OBSTRUCTED:
411 def8->SetNotObstructed(e.IsChecked());
412 def16->SetNotObstructed(e.IsChecked());
414 case SOUND_FLAGS_MOBSTRUCTED:
415 def8->SetNotMediaObstructed(e.IsChecked());
416 def16->SetNotMediaObstructed(e.IsChecked());
418 case SOUND_FLAGS_AMBIENT:
419 def8->SetAmbient(e.IsChecked());
420 def16->SetAmbient(e.IsChecked());
423 wxLogDebug(wxT("Invalid control id in FlagsChanged"));
426 GetDocument()->Modify(true);
429 void SoundsView::LowPitchValueChanged(wxScrollEvent &e)
433 sound_low_pitch_field->GetValue().ToLong(&l);
435 SoundsDefinition *def = payload->Get8BitSoundDefinition(mSoundClass);
438 def = payload->Get16BitSoundDefinition(mSoundClass);
440 GetDocument()->Modify(true);
443 void SoundsView::HighPitchValueChanged(wxScrollEvent &e)
447 sound_high_pitch_field->GetValue().ToLong(&l);
449 SoundsDefinition *def = payload->Get8BitSoundDefinition(mSoundClass);
450 def->SetHighPitch(l);
452 def = payload->Get16BitSoundDefinition(mSoundClass);
453 def->SetHighPitch(l);
454 GetDocument()->Modify(true);
457 void SoundsView::MenuDelete(wxCommandEvent &e)
459 wxWindow *win = sound_class_list->FindFocus();
461 switch (win->GetId()) {
462 case SOUND_CLASS_LIST:
463 wxLogDebug(wxT("Delete Sound Class"));
465 case SOUND_EIGHT_BIT_PERMUTATIONS_LIST:
466 case SOUND_SIXTEEN_BIT_PERMUTATIONS_LIST:
468 if (mSoundClass == wxNOT_FOUND || mSoundSource == wxNOT_FOUND || mSoundPermutation == wxNOT_FOUND) {
472 SoundsDefinition* def = payload->GetSoundDefinition(mSoundSource, mSoundClass);
473 def->DeletePermutation(mSoundPermutation);
475 GetDocument()->Modify(true);
483 void SoundsView::MenuAddSoundClass(wxCommandEvent &e)
485 wxLogDebug(wxT("Adding an item"));
486 payload->AddSoundDefinition();
488 // We add the new Sound class item by hand
489 sound_class_list->Append(wxString::Format(wxT("Sound %d"), sound_class_list->GetCount()));
491 GetDocument()->Modify(true);
496 void SoundsView::MenuImportSound(wxCommandEvent &e)
498 wxWindow* w = wxWindow::FindFocus();
499 SoundsDefinition* definition = 0;
500 if (w == static_cast<wxWindow*>(sound_sixteen_bit_list)) {
501 definition = payload->Get16BitSoundDefinition(mSoundClass);
502 } else if (w == static_cast<wxWindow*>(sound_eight_bit_list)) {
503 definition = payload->Get8BitSoundDefinition(mSoundClass);
505 wxMessageDialog msg(frame, wxT("Sorry, you need to select a sound class and 8-bit or 16-bit to import a sound"), wxT("Error: No selection"), wxOK | wxICON_EXCLAMATION);
510 if (definition->GetPermutationCount() >= MAXIMUM_PERMUTATIONS_PER_SOUND) {
511 wxMessageDialog msg(frame, wxT("There are already five permutations for this sound"), wxT("Error: permutation limit reached"), wxOK | wxICON_EXCLAMATION);
516 wxFileDialog dlg(frame, wxT("Choose a sound file to add"), wxT(""), wxT(""), wxT("Common sound files (AIFF, WAV)|*.aif;*.wav"), wxOPEN);
517 if (dlg.ShowModal() == wxID_OK) {
518 if (definition->NewPermutation(dlg.GetPath()) == NULL) {
519 wxMessageDialog msg(frame, wxT("Error importing sound"), wxT("Error"), wxOK | wxICON_EXCLAMATION);
525 GetDocument()->Modify(true);
530 void SoundsView::MenuExportSound(wxCommandEvent &e)
532 if (mSoundClass == wxNOT_FOUND || mSoundSource == wxNOT_FOUND || mSoundPermutation == wxNOT_FOUND) {
533 wxMessageDialog msg(frame, wxT("Sorry, you need to select a sound class and a permutation to export a sound"), wxT("Error : No selection"), wxOK | wxICON_EXCLAMATION);
538 wxFileDialog dlg(frame, wxT("Choose a file name :"), wxT(""), wxString::Format(wxT("Sound %d-%d.wav"), mSoundClass, mSoundPermutation), wxT("WAV files (*.wav)|*.wav|AIFF files (*.aif)|*.aif"), wxSAVE | wxOVERWRITE_PROMPT);
540 if (dlg.ShowModal() == wxID_OK) {
541 SoundsDefinition *def = payload->GetSoundDefinition(mSoundSource, mSoundClass);
542 AppleSoundHeader *sound = def->GetPermutation(mSoundPermutation);
545 switch (dlg.GetFilterIndex()) {
546 case 0: // Selected *.wav
547 result = sound->SaveToWave(dlg.GetPath());
549 case 1: // Selected *.aif
550 result = sound->SaveToAiff(dlg.GetPath());
557 wxLogDebug(wxT("[SoundsView] Error exporting sound"));
561 void SoundsView::SoundPermutationSelected(wxCommandEvent &e)
563 // We unselect the other permutation field
564 if (e.GetId() == SOUND_EIGHT_BIT_PERMUTATIONS_LIST) {
565 wxLogDebug(wxT("Selected 8-bit"));
566 sound_sixteen_bit_list->SetSelection(wxNOT_FOUND);
568 mSoundPermutation = sound_eight_bit_list->GetSelection();
569 } else if (e.GetId() == SOUND_SIXTEEN_BIT_PERMUTATIONS_LIST) {
570 wxLogDebug(wxT("Selected 16-bit"));
571 sound_eight_bit_list->SetSelection(wxNOT_FOUND);
573 mSoundPermutation = sound_sixteen_bit_list->GetSelection();
577 void SoundsView::SoundPermutationDoubleClicked(wxCommandEvent &e)
579 SoundsDefinition *def = payload->GetSoundDefinition(mSoundSource, mSoundClass);
580 def->GetPermutation(mSoundPermutation)->PlaySound();