2 #pragma warning(disable : 4786)
10 #include "DeviceFrame.h"
11 #include "SoundEffectFrame.h"
12 #include "StreamFrame.h"
15 #if wxCHECK_VERSION(2,5,3)
16 #include "wx/generic/numdlgg.h"
22 const std::string
& joiner
,
23 const std::string
& prefix
= "")
27 typename
T::iterator i
= cont
.begin();
29 result
+= prefix
+ *i
++;
30 if (i
== cont
.end()) {
41 BEGIN_EVENT_TABLE(DeviceFrame
, wxMDIParentFrame
)
42 EVT_MENU(DEVICE_NEW_DEVICE
, DeviceFrame::OnDeviceNewDevice
)
43 EVT_MENU(DEVICE_NEW_CDDEVICE
, DeviceFrame::OnDeviceNewCDDevice
)
44 EVT_MENU(DEVICE_NEW_MIDIDEVICE
, DeviceFrame::OnDeviceNewMIDIDevice
)
45 EVT_MENU(DEVICE_OPEN_STREAM
, DeviceFrame::OnDeviceOpenStream
)
46 EVT_MENU(DEVICE_OPEN_SOUND
, DeviceFrame::OnDeviceOpenSound
)
47 EVT_MENU(DEVICE_CREATE_TONE
, DeviceFrame::OnDeviceCreateTone
)
48 EVT_MENU(DEVICE_CREATE_SQUARE_WAVE
, DeviceFrame::OnDeviceCreateSquareWave
)
49 EVT_MENU(DEVICE_CREATE_WHITE_NOISE
, DeviceFrame::OnDeviceCreateWhiteNoise
)
50 EVT_MENU(DEVICE_CREATE_PINK_NOISE
, DeviceFrame::OnDeviceCreatePinkNoise
)
51 EVT_MENU(DEVICE_OPEN_SINGLE_EFFECT
, DeviceFrame::OnDeviceOpenSingleEffect
)
52 EVT_MENU(DEVICE_OPEN_MULTIPLE_EFFECT
, DeviceFrame::OnDeviceOpenMultipleEffect
)
53 EVT_MENU(DEVICE_CLOSE_WINDOW
, DeviceFrame::OnDeviceCloseCurrentWindow
)
54 EVT_MENU(DEVICE_CLOSE
, DeviceFrame::OnDeviceClose
)
55 EVT_MENU(HELP_ABOUT
, DeviceFrame::OnHelpAbout
)
59 DeviceFrame::DeviceFrame(audiere::AudioDevicePtr device
)
60 : wxMDIParentFrame(0, -1, wxT("Audio Device - " + CStr2wxString( device
->getName() )),
61 wxDefaultPosition
, wxSize(400, 500))
65 wxMenu
* deviceMenu
= new wxMenu();
66 deviceMenu
->Append(DEVICE_NEW_DEVICE
, wxT("&New Device..."));
67 deviceMenu
->Append(DEVICE_NEW_CDDEVICE
, wxT("New C&D Device..."));
68 deviceMenu
->Append(DEVICE_NEW_MIDIDEVICE
, wxT("New &MIDI Device..."));
69 deviceMenu
->AppendSeparator();
70 deviceMenu
->Append(DEVICE_OPEN_STREAM
, wxT("&Open Stream..."));
71 deviceMenu
->Append(DEVICE_OPEN_SOUND
, wxT("Open &Sound..."));
72 deviceMenu
->AppendSeparator();
73 deviceMenu
->Append(DEVICE_CREATE_TONE
, wxT("Create &Tone..."));
74 deviceMenu
->Append(DEVICE_CREATE_SQUARE_WAVE
, wxT("Create S&quare Wave..."));
75 deviceMenu
->Append(DEVICE_CREATE_WHITE_NOISE
, wxT("Create &White Noise"));
76 deviceMenu
->Append(DEVICE_CREATE_PINK_NOISE
, wxT("Create &Pink Noise"));
77 deviceMenu
->AppendSeparator();
78 deviceMenu
->Append(DEVICE_OPEN_SINGLE_EFFECT
, wxT("Open &Effect (Single)..."));
79 deviceMenu
->Append(DEVICE_OPEN_MULTIPLE_EFFECT
, wxT("Open Effect (&Multiple)..."));
80 deviceMenu
->AppendSeparator();
81 deviceMenu
->Append(DEVICE_CLOSE_WINDOW
, wxT("Close C&urrent Window"));
82 deviceMenu
->Append(DEVICE_CLOSE
, wxT("&Close Device"));
84 wxMenu
* helpMenu
= new wxMenu();
85 helpMenu
->Append(HELP_ABOUT
, wxT("&About..."));
87 wxMenuBar
* menuBar
= new wxMenuBar();
88 menuBar
->Append(deviceMenu
, wxT("&Device"));
89 menuBar
->Append(helpMenu
, wxT("&Help"));
96 void DeviceFrame::OnDeviceNewDevice(wxCommandEvent
&) {
97 wxGetApp().OnNewDevice(this);
101 void DeviceFrame::OnDeviceNewCDDevice(wxCommandEvent
&) {
102 wxGetApp().OnNewCDDevice(this);
106 void DeviceFrame::OnDeviceNewMIDIDevice(wxCommandEvent
&) {
107 wxGetApp().OnNewMIDIDevice(this);
111 wxString
DeviceFrame::GetSoundFile() {
112 std::vector
<audiere::FileFormatDesc
> formats
;
113 audiere::GetSupportedFileFormats(formats
);
115 // combine all of the supported extensions into one collection
116 std::set
<std::string
> all_extensions
;
118 for (unsigned i
= 0; i
< formats
.size(); ++i
) {
119 for (unsigned j
= 0; j
< formats
[i
].extensions
.size(); ++j
) {
120 all_extensions
.insert("*." + formats
[i
].extensions
[j
]);
125 // build a string of wildcards for wxWindows
126 std::string wildcards
;
127 wildcards
= "Sound Files (" + Join(all_extensions
, ",") + ")|";
128 wildcards
+= Join(all_extensions
, ";") + "|";
131 for (unsigned i
= 0; i
< formats
.size(); ++i
) {
132 audiere::FileFormatDesc
& ffd
= formats
[i
];
133 wildcards
+= ffd
.description
+ " ";
134 wildcards
+= "(" + Join(ffd
.extensions
, ",", "*.") + ")|";
135 wildcards
+= Join(ffd
.extensions
, ";", "*.") + "|";
139 wildcards
+= "All Files (*.*)|*.*";
141 return wxFileSelector(
142 wxT("Select a sound file"), wxT(""), wxT(""), wxT(""),
143 CStr2wxString(wildcards
.c_str()), wxOPEN
, this);
147 void DeviceFrame::OnDeviceOpenStream(wxCommandEvent
&) {
148 wxString
filename(GetSoundFile());
149 if (filename
.empty()) {
154 wxCharBuffer buffFilename
= filename
.mb_str(wxConvUTF8
);
155 audiere::SampleSourcePtr source
= audiere::OpenSampleSource(buffFilename
.data());
157 audiere::SampleSourcePtr source
= audiere::OpenSampleSource(filename
);
161 wxT("Could not open sample source: ") + filename
,
162 wxT("Open Stream"), wxOK
| wxCENTRE
, this);
166 audiere::LoopPointSourcePtr loop_source
=
167 audiere::CreateLoopPointSource(source
);
169 source
= loop_source
.get();
172 audiere::OutputStreamPtr stream
= audiere::OpenSound(
178 wxT("Could not open output stream: ") + filename
,
179 wxT("Open Stream"), wxOK
| wxCENTRE
, this);
183 // get the basename of the path for the window title
184 wxString basename
= wxFileNameFromPath(filename
);
185 new StreamFrame(this, wxT("Stream: ") + basename
, stream
.get(), source
.get(), loop_source
.get());
189 void DeviceFrame::OnDeviceOpenSound(wxCommandEvent
&) {
190 wxString
filename(GetSoundFile());
191 if (filename
.empty()) {
195 audiere::SampleSourcePtr source
= audiere::OpenSampleSource(wxString2CStr(filename
));
198 wxT("Could not open source: ") + filename
,
199 wxT("Open Sound"), wxOK
| wxCENTRE
, this);
203 audiere::OutputStreamPtr stream
= audiere::OpenSound(m_device
, source
);
206 wxT("Could not open sound: ") + filename
,
207 wxT("Open Sound"), wxOK
| wxCENTRE
, this);
211 // get the basename of the path for the window title
212 wxString basename
= wxFileNameFromPath(filename
);
213 new StreamFrame(this, wxT("Sound: ") + basename
, stream
.get(), source
.get());
217 void DeviceFrame::OnDeviceCreateTone(wxCommandEvent
&) {
218 int frequency
= ::wxGetNumberFromUser(
219 wxT("Value must be between 1 and 30000."), wxT("Enter frequency in Hz"),
220 wxT("Create Tone"), 256, 1, 30000, this);
221 if (frequency
!= -1) {
222 audiere::SampleSourcePtr source
= audiere::CreateTone(frequency
);
225 wxT("Could not create tone"),
226 wxT("Create Tone"), wxOK
| wxCENTRE
, this);
230 audiere::OutputStreamPtr stream
= m_device
->openStream(source
.get());
233 wxT("Could not open output stream"),
234 wxT("Create Tone"), wxOK
| wxCENTRE
, this);
240 title
.sprintf(wxT("Tone: %d Hz"), frequency
);
241 new StreamFrame(this, title
, stream
.get(), source
.get());
246 void DeviceFrame::OnDeviceCreateSquareWave(wxCommandEvent
&) {
247 int frequency
= ::wxGetNumberFromUser(
248 wxT("Value must be between 1 and 30000."), wxT("Enter frequency in Hz"),
249 wxT("Create Square Wave"), 256, 1, 30000, this);
250 if (frequency
!= -1) {
251 audiere::SampleSourcePtr source
= audiere::CreateSquareWave(frequency
);
254 wxT("Could not create square wave"),
255 wxT("Create Square Wave"), wxOK
| wxCENTRE
, this);
259 audiere::OutputStreamPtr stream
= m_device
->openStream(source
.get());
262 wxT("Could not open output stream"),
263 wxT("Create Square Wave"), wxOK
| wxCENTRE
, this);
268 title
.sprintf(wxT("Square Wave: %d Hz"), frequency
);
269 new StreamFrame(this, title
, stream
.get(), source
.get());
274 void DeviceFrame::OnDeviceCreateWhiteNoise(wxCommandEvent
&) {
275 audiere::SampleSourcePtr source
= audiere::CreateWhiteNoise();
278 wxT("Could not create white noise"),
279 wxT("Create White Noise"), wxOK
| wxCENTRE
, this);
283 audiere::OutputStreamPtr stream
= m_device
->openStream(source
.get());
286 wxT("Could not open output stream"),
287 wxT("Create White Noise"), wxOK
| wxCENTRE
, this);
291 new StreamFrame(this, wxT("White Noise"), stream
.get(), source
.get());
295 void DeviceFrame::OnDeviceCreatePinkNoise(wxCommandEvent
&) {
296 audiere::SampleSourcePtr source
= audiere::CreatePinkNoise();
299 wxT("Could not create white noise"),
300 wxT("Create Pink Noise"), wxOK
| wxCENTRE
, this);
304 audiere::OutputStreamPtr stream
= m_device
->openStream(source
.get());
307 wxT("Could not open output stream"),
308 wxT("Create Pink Noise"), wxOK
| wxCENTRE
, this);
312 new StreamFrame(this, wxT("Pink Noise"), stream
.get(), source
.get());
316 void DeviceFrame::OnDeviceOpenSingleEffect(wxCommandEvent
&) {
317 DoOpenEffect(audiere::SINGLE
, wxT("Single"));
321 void DeviceFrame::OnDeviceOpenMultipleEffect(wxCommandEvent
&) {
322 DoOpenEffect(audiere::MULTIPLE
, wxT("Multiple"));
326 void DeviceFrame::DoOpenEffect(audiere::SoundEffectType type
, wxString typestring
) {
327 wxString
filename(GetSoundFile());
328 if (filename
.empty()) {
332 audiere::SoundEffectPtr effect
= audiere::OpenSoundEffect(m_device
, wxString2CStr(filename
), type
);
334 wxString basename
= wxFileNameFromPath(filename
);
336 title
.sprintf(wxT("Sound Effect (%s): %s"),
337 typestring
.c_str(), basename
.c_str());
338 new SoundEffectFrame(this, title
, effect
);
341 wxT("Could not open sound effect: ") + filename
,
342 wxT("Open Sound Effect"), wxOK
| wxCENTRE
, this);
347 void DeviceFrame::OnDeviceCloseCurrentWindow(wxCommandEvent
&) {
348 wxMDIChildFrame
* frame
= GetActiveChild();
355 void DeviceFrame::OnDeviceClose(wxCommandEvent
&) {
360 void DeviceFrame::OnHelpAbout(wxCommandEvent
&) {
361 wxGetApp().ShowAboutDialog(this);