1 #ifdef _MSC_VER
2 #pragma warning(disable : 4786)
3 #endif
4 
5 
6 #include "Commands.h"
7 #include "MIDIDeviceFrame.h"
8 #include "MIDIStreamFrame.h"
9 #include "wxPlayer.h"
10 
11 
BEGIN_EVENT_TABLE(MIDIDeviceFrame,wxMDIParentFrame)12 BEGIN_EVENT_TABLE(MIDIDeviceFrame, wxMDIParentFrame)
13   EVT_MENU(DEVICE_NEW_DEVICE,     MIDIDeviceFrame::OnDeviceNewDevice)
14   EVT_MENU(DEVICE_NEW_CDDEVICE,   MIDIDeviceFrame::OnDeviceNewCDDevice)
15   EVT_MENU(DEVICE_NEW_MIDIDEVICE, MIDIDeviceFrame::OnDeviceNewMIDIDevice)
16   EVT_MENU(DEVICE_OPEN_SONG,      MIDIDeviceFrame::OnDeviceOpenSong)
17   EVT_MENU(DEVICE_CLOSE_WINDOW,   MIDIDeviceFrame::OnDeviceCloseCurrentWindow)
18   EVT_MENU(DEVICE_CLOSE,          MIDIDeviceFrame::OnDeviceClose)
19   EVT_MENU(HELP_ABOUT,            MIDIDeviceFrame::OnHelpAbout)
20 END_EVENT_TABLE()
21 
22 
23 MIDIDeviceFrame::MIDIDeviceFrame(audiere::MIDIDevicePtr device)
24 : wxMDIParentFrame(0, -1, wxT("MIDI Device - ") + CStr2wxString(device->getName()),
25                    wxDefaultPosition, wxSize(400, 500))
26 {
27   m_device = device;
28 
29   wxMenu* deviceMenu = new wxMenu;
30   deviceMenu->Append(DEVICE_NEW_DEVICE,     wxT("&New Device..."));
31   deviceMenu->Append(DEVICE_NEW_CDDEVICE,   wxT("New C&D Device..."));
32   deviceMenu->Append(DEVICE_NEW_MIDIDEVICE, wxT("New &MIDI Device..."));
33   deviceMenu->AppendSeparator();
34   deviceMenu->Append(DEVICE_OPEN_SONG,      wxT("Open &Song..."));
35   deviceMenu->AppendSeparator();
36   deviceMenu->Append(DEVICE_CLOSE_WINDOW,   wxT("Close C&urrent Window"));
37   deviceMenu->Append(DEVICE_CLOSE,          wxT("&Close Device"));
38 
39   wxMenu* helpMenu = new wxMenu;
40   helpMenu->Append(HELP_ABOUT, wxT("&About..."));
41 
42   wxMenuBar* menuBar = new wxMenuBar;
43   menuBar->Append(deviceMenu, wxT("&Device"));
44   menuBar->Append(helpMenu,   wxT("&Help"));
45   SetMenuBar(menuBar);
46 
47   SetFocus();
48 }
49 
50 
OnDeviceNewDevice(wxCommandEvent &)51 void MIDIDeviceFrame::OnDeviceNewDevice(wxCommandEvent&) {
52   wxGetApp().OnNewDevice(this);
53 }
54 
55 
OnDeviceNewCDDevice(wxCommandEvent &)56 void MIDIDeviceFrame::OnDeviceNewCDDevice(wxCommandEvent&) {
57   wxGetApp().OnNewCDDevice(this);
58 }
59 
60 
OnDeviceNewMIDIDevice(wxCommandEvent &)61 void MIDIDeviceFrame::OnDeviceNewMIDIDevice(wxCommandEvent&) {
62   wxGetApp().OnNewMIDIDevice(this);
63 }
64 
65 
OnDeviceOpenSong(wxCommandEvent &)66 void MIDIDeviceFrame::OnDeviceOpenSong(wxCommandEvent&) {
67   wxString file = wxFileSelector(
68     wxT("Select a MIDI file"), wxT(""), wxT(""), wxT(""),
69    wxT( "MIDI Files (*.midi,*.mid,*.rmi)|*.midi;*.mid;*.rmi|")
70     wxT("All Files (*.*)|*.*"),
71     wxOPEN, this);
72   if (!file.empty()) {
73     audiere::MIDIStreamPtr stream = m_device->openStream(wxString2CStr(file));
74     if (!stream) {
75       wxMessageBox(
76         wxT("Could not open MIDI file: ") + file,
77         wxT("Open MIDI File"), wxOK | wxCENTRE, this);
78     }
79 
80     new MIDIStreamFrame(this, wxT("MIDI File - ") + file, stream);
81   }
82 }
83 
84 
OnDeviceCloseCurrentWindow(wxCommandEvent &)85 void MIDIDeviceFrame::OnDeviceCloseCurrentWindow(wxCommandEvent&) {
86   wxMDIChildFrame* frame = GetActiveChild();
87   if (frame) {
88     frame->Close();
89   }
90 }
91 
92 
OnDeviceClose(wxCommandEvent &)93 void MIDIDeviceFrame::OnDeviceClose(wxCommandEvent&) {
94   Close();
95 }
96 
97 
OnHelpAbout(wxCommandEvent &)98 void MIDIDeviceFrame::OnHelpAbout(wxCommandEvent&) {
99   wxGetApp().ShowAboutDialog(this);
100 }
101