www.pudn.com > EndpointDetection_Pitch.zip > PitchDlg.cpp
// PitchDlg.cpp : implementation file // #include "stdafx.h" #include "Pitch.h" #include "PitchDlg.h" #include "PerfDlg.h" #include "RelDlg.h" #include "Preferences.h" #include "Chords.h" #include#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // #define PLAY_BUFFER_LENGTH 128 #define MAX_NUM_DEVICES 8 // max # of MIDI input devices extern int MainX, MainY, MainWidth, MainHeight; extern int LowPianoNote; int LowPianoNote = 25; extern int HighPianoNote; int HighPianoNote = 104; extern BYTE InstrumentNumber; extern BYTE CurrentChannel; BYTE CurrentChannel = '\x00'; extern BYTE bStatus; BYTE bStatus; // Midi status byte extern BYTE bChannel; BYTE bChannel; // Midi channel byte extern BYTE bData1; BYTE bData1; // First midi data byte extern BYTE bData2; BYTE bData2; // Second midi data byte extern int NoteWaitTimeLength; int NoteWaitTimeLength = 250; // Preferences externs are resident in this file extern int IncorrectDialogSwitch; int IncorrectDialogSwitch = 0; // default of no dialog extern char NoteTable2[]; extern int currentDialog; MSG CommonMessage; CMenu menu; WORD wNumDevices = 0; // Number of MIDI input devices opened WORD wRtn; UINT wDeviceID; DWORD dwReturn; UINT UResult; MCI_OPEN_PARMS mciOpenParms; MCI_PLAY_PARMS mciPlayParms; MCI_STATUS_PARMS mciStatusParms; MCI_SEQ_SET_PARMS mciSeqSetParms; MIDIOUTCAPS midiOutCaps[MAX_NUM_DEVICES]; HMIDIOUT hMidiOut; // Handle to the midi device // Timer globals HWND hwnd; UINT SetTimer(HWND, UINT, int ,DWORD); // Prototype char szErrorText[80]; unsigned int i, j; int SubMenuGroup, SubItem; extern int NoteLength; long MidiErr ; char strError[64]; long strPort = 0; int NotePosition; static char MidiReturn[128]; int HighNoteForSoundBlaster = 75; int HighNoteForRoland = 95; char NoteTable1[320] = "C0 C\x23" "0D0 D\x23" "0E0 F0 F\x23" "0G0 G\x23" "0A0 A\x23" "0B0 " "C1 C\x23" "1D1 D\x23" "1E1 F1 F\x23" "1G1 G\x23" "1A1 A\x23" "1B1 " "C2 C\x23" "2D2 D\x23" "2E2 F2 F\x23" "2G2 G\x23" "2A2 A\x23" "2B2 " "C3 C\x23" "3D3 D\x23" "3E3 F3 F\x23" "3G3 G\x23" "3A3 A\x23" "3B3 " "C4 C\x23" "4D4 D\x23" "4E4 F4 F\x23" "4G4 G\x23" "4A4 A\x23" "4B4 " "C5 C\x23" "5D5 D\x23" "5E5 F5 F\x23" "5G5 G\x23" "5A5 A\x23" "5B5 " "C6 C\x23" "6D6 D\x23" "6E6 F6 F\x23" "6G6 G\x23" "6A6 A\x23" "6B6 " "C7 C\x23" "7D7 D\x23" "7E7 F7 F\x23" "7G7 G\x23" "7A7 A\x23" "7B7 " "C8 C\x23" "8D8 D\x23" "8E8 F8 F\x23" "8G8 " ; // The following hex "23" codes are the ascii # to represent sharps char NoteTable2[25] = "A " "A\x23" "B " "C " "C\x23" "D " "D\x23" "E " "F " "F\x23" "G " "G\x23"; char NoteDescription[32]; // Following table is mapped notes played by note answers // Each row is a note played and each column is a note answer // The first column is number of times the note was played // The second column is the number of times the note answer was correct // The 3rd through 14th columns are the note results unsigned int PerfectNoteResults[12][14]; unsigned int RelativeNoteResults[13][15]; ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPitchDlg dialog CPitchDlg::CPitchDlg(CWnd* pParent /*=NULL*/) : CDialog(CPitchDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPitchDlg) //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CPitchDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPitchDlg) DDX_Control(pDX, IDC_GetOut, m_GetOutCommand); DDX_Control(pDX, IDC_Help_Command, m_HelpCommand); DDX_Control(pDX, IDC_ChordsCommand, m_ChordsCommand); DDX_Control(pDX, IDC_PerfectPitchCommand, m_PerfectPitchCommand); DDX_Control(pDX, IDC_RelativePitchCommand, m_RelativePitchCommand); DDX_Control(pDX, IDC_PitchTitle, m_PitchTitle); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPitchDlg, CDialog) //{{AFX_MSG_MAP(CPitchDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_RBUTTONDOWN() ON_COMMAND(ID_PORT0, OnPort0) ON_COMMAND(ID_PORT1, OnPort1) ON_COMMAND(ID_PORT2, OnPort2) ON_COMMAND(ID_PORT3, OnPort3) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT001, OnInstrument001) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT002, OnInstrument002) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT003, OnInstrument003) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT004, OnInstrument004) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT005, OnInstrument005) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT006, OnInstrument006) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT007, OnInstrument007) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT008, OnInstrument008) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT009, OnInstrument009) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT010, OnInstrument010) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT011, OnInstrument011) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT012, OnInstrument012) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT013, OnInstrument013) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT014, OnInstrument014) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT015, OnInstrument015) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT016, OnInstrument016) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT017, OnInstrument017) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT018, OnInstrument018) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT019, OnInstrument019) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT020, OnInstrument020) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT021, OnInstrument021) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT022, OnInstrument022) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT023, OnInstrument023) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT024, OnInstrument024) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT025, OnInstrument025) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT026, OnInstrument026) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT027, OnInstrument027) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT028, OnInstrument028) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT029, OnInstrument029) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT030, OnInstrument030) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT031, OnInstrument031) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT032, OnInstrument032) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT033, OnInstrument033) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT034, OnInstrument034) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT035, OnInstrument035) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT036, OnInstrument036) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT037, OnInstrument037) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT038, OnInstrument038) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT039, OnInstrument039) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT040, OnInstrument040) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT041, OnInstrument041) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT042, OnInstrument042) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT043, OnInstrument043) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT044, OnInstrument044) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT045, OnInstrument045) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT046, OnInstrument046) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT047, OnInstrument047) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT048, OnInstrument048) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT049, OnInstrument049) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT050, OnInstrument050) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT051, OnInstrument051) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT052, OnInstrument052) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT053, OnInstrument053) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT055, OnInstrument055) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT054, OnInstrument054) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT056, OnInstrument056) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT057, OnInstrument057) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT058, OnInstrument058) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT059, OnInstrument059) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT060, OnInstrument060) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT061, OnInstrument061) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT062, OnInstrument062) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT063, OnInstrument063) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT064, OnInstrument064) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT065, OnInstrument065) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT066, OnInstrument066) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT067, OnInstrument067) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT068, OnInstrument068) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT069, OnInstrument069) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT070, OnInstrument070) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT071, OnInstrument071) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT072, OnInstrument072) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT073, OnInstrument073) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT074, OnInstrument074) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT075, OnInstrument075) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT076, OnInstrument076) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT077, OnInstrument077) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT078, OnInstrument078) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT079, OnInstrument079) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT080, OnInstrument080) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT081, OnInstrument081) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT082, OnInstrument082) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT083, OnInstrument083) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT084, OnInstrument084) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT085, OnInstrument085) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT086, OnInstrument086) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT087, OnInstrument087) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT088, OnInstrument088) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT089, OnInstrument089) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT090, OnInstrument090) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT091, OnInstrument091) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT092, OnInstrument092) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT093, OnInstrument093) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT094, OnInstrument094) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT095, OnInstrument095) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT096, OnInstrument096) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT097, OnInstrument097) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT098, OnInstrument098) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT099, OnInstrument099) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT100, OnInstrument100) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT101, OnInstrument101) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT102, OnInstrument102) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT103, OnInstrument103) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT104, OnInstrument104) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT105, OnInstrument105) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT106, OnInstrument106) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT107, OnInstrument107) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT108, OnInstrument108) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT109, OnInstrument109) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT110, OnInstrument110) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT111, OnInstrument111) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT112, OnInstrument112) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT113, OnInstrument113) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT114, OnInstrument114) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT115, OnInstrument115) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT116, OnInstrument116) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT117, OnInstrument117) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT118, OnInstrument118) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT119, OnInstrument119) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT120, OnInstrument120) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT121, OnInstrument121) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT122, OnInstrument122) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT123, OnInstrument123) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT124, OnInstrument124) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT125, OnInstrument125) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT126, OnInstrument126) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT127, OnInstrument127) ON_COMMAND(ID_MAINPOPUP_INSTRUMENT128, OnInstrument128) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_100, OnMainPopupNoteLength100) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_250, OnMainPopupNoteLength250) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_500, OnMainPopupNoteLength500) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_750, OnMainPopupNoteLength750) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_1000, OnMainPopupNoteLength1000) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_2000, OnMainPopupNoteLength2000) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_3000, OnMainPopupNoteLength3000) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_4000, OnMainPopupNoteLength4000) ON_COMMAND(ID_MAINPOPUP_NOTELENGTH_5000, OnMainPopupNoteLength5000) ON_COMMAND(ID_MAINPOPUP_PREFERENCES, OnShowPreferences) ON_WM_CTLCOLOR() ON_WM_DESTROY() ON_BN_CLICKED(IDC_PerfectPitchCommand, OnPerfectPitchCommand) ON_BN_CLICKED(IDC_RelativePitchCommand, OnRelativePitchCommand) ON_BN_CLICKED(IDC_ChordsCommand, OnChordsCommand) ON_BN_CLICKED(IDC_Help_Command, OnHelpCommand) ON_BN_CLICKED(IDC_GetOut, OnGetOut) ON_BN_CLICKED(IDC_PitchTitle, OnPitchTitle) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPitchDlg message handlers BOOL CPitchDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here int cx = ::GetSystemMetrics(SM_CXSCREEN); int cy = ::GetSystemMetrics(SM_CYSCREEN); VERIFY(menu.LoadMenu(IDR_POPUP_MAINMENU)); m_PerfectPitchCommand.SetShade(SHS_METAL,8,30); m_PerfectPitchCommand.SetTextColor(PurpleColour); m_PerfectPitchCommand.SetFont("Signature",24,20); m_RelativePitchCommand.SetShade(SHS_METAL,8,30); m_RelativePitchCommand.SetTextColor(PurpleColour); m_RelativePitchCommand.SetFont("Signature",24,20); m_ChordsCommand.SetShade(SHS_METAL,8,30); m_ChordsCommand.SetTextColor(PurpleColour); m_ChordsCommand.SetFont("Signature",24,20); m_HelpCommand.SetShade(SHS_SOFTBUMP,6,30); m_HelpCommand.SetTextColor(BlueColour); m_HelpCommand.SetFont("Signature",24,20); m_GetOutCommand.SetShade(SHS_SOFTBUMP,6,30); m_GetOutCommand.SetTextColor(RedColour); m_GetOutCommand.SetFont("Signature",24,20); m_PitchTitle.SetShade(SHS_METAL,8,30); m_PitchTitle.SetTextColor(PurpleColour); m_PitchTitle.SetFont("Signature",72,20); m_PitchTitle.SetWindowText("Pitch"); // m_PitchTitle.SetBitmap(IDB_PitchBitmap); // Set the main window to where it finished last time MoveWindow(MainX, MainY, MainWidth, MainHeight, TRUE); // Initialise PerfectNoteResults table to zeroes for (int i = 0; i<12;i++) {for (int j = 0;j<14;j++) {PerfectNoteResults[i][j] = 0;} }; srand((unsigned)time(NULL)); // Ensure new set of random numbers each execution // Set instrument, time played and port to last used UpdateInstrument(InstrumentNumber); UpdateNoteLength(NoteLength); // Get the number of devices and their capabilities wNumDevices = midiOutGetNumDevs(); if (!wNumDevices) {MessageBox("There are no MIDI output devices.");}; for (i=0; (i GetSubMenu(2); wRtn = 1; while (wRtn) {wRtn = pPortPopup->DeleteMenu(0, MF_BYPOSITION);}; // Add ports separately as the UINT method did not work for me // The user must decide where he has his cables connected and if system.ini has a port setup pPortPopup->AppendMenu (MF_STRING | MF_ENABLED | MF_CHECKED , (UINT) ID_PORT0,midiOutCaps[0].szPname); if (wNumDevices < 2) {goto EndOfPorts;}; pPortPopup->AppendMenu (MF_STRING | MF_ENABLED , (UINT) ID_PORT1,midiOutCaps[1].szPname); if (wNumDevices < 3) {goto EndOfPorts;}; pPortPopup->AppendMenu (MF_STRING | MF_ENABLED , (UINT) ID_PORT2,midiOutCaps[2].szPname); if (wNumDevices < 4) {goto EndOfPorts;}; pPortPopup->AppendMenu (MF_STRING | MF_ENABLED , (UINT) ID_PORT3,midiOutCaps[3].szPname); EndOfPorts: wDeviceID = mciOpenParms.wDeviceID; UResult = midiOutOpen(&hMidiOut,wDeviceID, NULL,NULL,CALLBACK_NULL); ShowError(); return TRUE; // return TRUE unless you set the focus to a control } void CPitchDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CPitchDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CPitchDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CPitchDlg::OnRelativePitchCommand() { CRelDlg dlg; dlg.DoModal(); } void CPitchDlg::OnPerfectPitchCommand() { CPerfDlg dlg; dlg.DoModal(); } void CPitchDlg::OnChordsCommand() { CChords dlg; dlg.DoModal(); } ////////////////////////////////////////////////////////////////////////////// //////Following routine returns a random nuber within the parameters requested ////////////////////////////////////////////////////////////////////////////// int CPitchDlg::GetARandomNumber(int LowRange, int HighRange) { int RandomNumber; char RandomChar[3]; sprintf(RandomChar,"%d",rand()%(HighRange-LowRange+1)); // Number returned is from 0->size of range less one RandomNumber = atoi(RandomChar); RandomNumber = RandomNumber + LowRange; return(RandomNumber); } BEGIN_EVENTSINK_MAP(CPitchDlg, CDialog) //{{AFX_EVENTSINK_MAP(CPitchDlg) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() void CPitchDlg::OnGetOut() { CDialog::OnOK(); } void CPitchDlg::OnRButtonDown(UINT nFlags, CPoint point) { // Display the pop up menu seection on right mouse button down int x; int y; // Have to find out where our dialog is presently sitting CRect rect; CPoint TL; GetWindowRect(&rect); TL = rect.TopLeft(); MainX = TL.x; MainY = TL.y; x = point.x; y = point.y; x = x+MainX+20; y = y+MainY+17; ProcessPopupMenu(x,y); CDialog::OnRButtonDown(nFlags, point); } void CPitchDlg::ProcessPopupMenu(int x,int y) { CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, AfxGetMainWnd()); } void CPitchDlg::OnPort0() { strPort=0; UpdatePort(strPort); } void CPitchDlg::OnPort1() { strPort=1; UpdatePort(strPort); } void CPitchDlg::OnPort2() { strPort=2; UpdatePort(strPort); } void CPitchDlg::OnPort3() { strPort=3; UpdatePort(strPort); } void CPitchDlg::OnInstrument001() { InstrumentNumber = 0; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument002() { InstrumentNumber = 1; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument003() { InstrumentNumber = 2; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument004() { InstrumentNumber = 3; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument005() { InstrumentNumber = 4; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument006() { InstrumentNumber = 5; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument007() { InstrumentNumber = 6; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument008() { InstrumentNumber = 7; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument009() { InstrumentNumber = 8; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument010() { InstrumentNumber = 9; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument011() { InstrumentNumber = 10; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument012() { InstrumentNumber = 11; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument013() { InstrumentNumber = 12; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument014() { InstrumentNumber = 13; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument015() { InstrumentNumber = 14; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument016() { InstrumentNumber = 15; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument017() { InstrumentNumber = 16; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument018() { InstrumentNumber = 17; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument019() { InstrumentNumber = 18; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument020() { InstrumentNumber = 19; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument021() { InstrumentNumber = 20; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument022() { InstrumentNumber = 21; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument023() { InstrumentNumber = 22; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument024() { InstrumentNumber = 23; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument025() { InstrumentNumber = 24; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument026() { InstrumentNumber = 25; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument027() { InstrumentNumber = 26; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument028() { InstrumentNumber = 27; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument029() { InstrumentNumber = 28; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument030() { InstrumentNumber = 29; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument031() { InstrumentNumber = 30; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument032() { InstrumentNumber = 31; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument033() { InstrumentNumber = 32; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument034() { InstrumentNumber = 33; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument035() { InstrumentNumber = 34; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument036() { InstrumentNumber = 35; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument037() { InstrumentNumber = 36; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument038() { InstrumentNumber = 37; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument039() { InstrumentNumber = 38; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument040() { InstrumentNumber = 39; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument041() { InstrumentNumber = 40; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument042() { InstrumentNumber = 41; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument043() { InstrumentNumber = 42; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument044() { InstrumentNumber = 43; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument045() { InstrumentNumber = 44; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument046() { InstrumentNumber = 45; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument047() { InstrumentNumber = 46; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument048() { InstrumentNumber = 47; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument049() { InstrumentNumber = 48; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument050() { InstrumentNumber = 49; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument051() { InstrumentNumber = 50; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument052() { InstrumentNumber = 51; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument053() { InstrumentNumber = 52; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument054() { InstrumentNumber = 53; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument055() { InstrumentNumber = 54; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument056() { InstrumentNumber = 55; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument057() { InstrumentNumber = 56; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument058() { InstrumentNumber = 57; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument059() { InstrumentNumber = 58; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument060() { InstrumentNumber = 59; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument061() { InstrumentNumber = 60; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument062() { InstrumentNumber = 61; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument063() { InstrumentNumber = 62; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument064() { InstrumentNumber = 63; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument065() { InstrumentNumber = 64; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument066() { InstrumentNumber = 65; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument067() { InstrumentNumber = 66; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument068() { InstrumentNumber = 67; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument069() { InstrumentNumber = 68; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument070() { InstrumentNumber = 69; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument071() { InstrumentNumber = 70; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument072() { InstrumentNumber = 71; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument073() { InstrumentNumber = 72; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument074() { InstrumentNumber = 73; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument075() { InstrumentNumber = 74; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument076() { InstrumentNumber = 75; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument077() { InstrumentNumber = 76; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument078() { InstrumentNumber = 77; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument079() { InstrumentNumber = 78; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument080() { InstrumentNumber = 79; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument081() { InstrumentNumber = 80; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument082() { InstrumentNumber = 81; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument083() { InstrumentNumber = 82; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument084() { InstrumentNumber = 83; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument085() { InstrumentNumber = 84; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument086() { InstrumentNumber = 85; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument087() { InstrumentNumber = 86; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument088() { InstrumentNumber = 87; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument089() { InstrumentNumber = 88; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument090() { InstrumentNumber = 89; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument091() { InstrumentNumber = 90; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument092() { InstrumentNumber = 91; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument093() { InstrumentNumber = 92; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument094() { InstrumentNumber = 93; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument095() { InstrumentNumber = 94; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument096() { InstrumentNumber = 95; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument097() { InstrumentNumber = 96; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument098() { InstrumentNumber = 97; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument099() { InstrumentNumber = 98; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument100() { InstrumentNumber = 99; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument101() { InstrumentNumber = 100; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument102() { InstrumentNumber = 101; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument103() { InstrumentNumber = 102; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument104() { InstrumentNumber = 103; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument105() { InstrumentNumber = 104; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument106() { InstrumentNumber = 105; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument107() { InstrumentNumber = 106; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument108() { InstrumentNumber = 107; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument109() { InstrumentNumber = 108; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument110() { InstrumentNumber = 109; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument111() { InstrumentNumber = 110; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument112() { InstrumentNumber = 111; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument113() { InstrumentNumber = 112; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument114() { InstrumentNumber = 113; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument115() { InstrumentNumber = 114; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument116() { InstrumentNumber = 115; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument117() { InstrumentNumber = 116; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument118() { InstrumentNumber = 117; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument119() { InstrumentNumber = 118; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument120() { InstrumentNumber = 119; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument121() { InstrumentNumber = 120; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument122() { InstrumentNumber = 121; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument123() { InstrumentNumber = 122; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument124() { InstrumentNumber = 123; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument125() { InstrumentNumber = 124; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument126() { InstrumentNumber = 125; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument127() { InstrumentNumber = 126; UpdateInstrument(InstrumentNumber);} void CPitchDlg::OnInstrument128() { InstrumentNumber = 127; UpdateInstrument(InstrumentNumber);} void CPitchDlg::UpdateInstrument(int MyInstrumentNumber) { // SubItem and SubMenuGroup are only calculated her and used when // tracking the popup menu SubMenuGroup = (MyInstrumentNumber/8) ; SubItem = MyInstrumentNumber%8; UINT InstrumentItems, LevelItems, PortItems, InstrumentGroup0Items; //CMenu menu; CMenu* pTopLevelPopup = menu.GetSubMenu(0); //ASSERT(pPopup != NULL); CMenu* pInstrumentGroupPopup = pTopLevelPopup->GetSubMenu(0); CMenu* pLevelPopup = pTopLevelPopup->GetSubMenu(1); CMenu* pPortPopup = pTopLevelPopup->GetSubMenu(2); InstrumentItems = pInstrumentGroupPopup->GetMenuItemCount(); LevelItems = pLevelPopup->GetMenuItemCount(); PortItems = pPortPopup->GetMenuItemCount(); CMenu* pInstrumentGroup0Popup = pInstrumentGroupPopup->GetSubMenu(0); InstrumentGroup0Items = pInstrumentGroup0Popup->GetMenuItemCount(); pInstrumentGroupPopup->CheckMenuItem(SubMenuGroup,MF_UNCHECKED| MF_BYPOSITION); // Uncheck all boxes for (i = 0; i < 16; i++) { CMenu* pMenuInstruments = pInstrumentGroupPopup->GetSubMenu(i); for (j = 0; j < 8; j++) {pMenuInstruments->CheckMenuItem(j,MF_UNCHECKED| MF_BYPOSITION);}; }; // Now check the one the user ticked CMenu* pMenuInstruments = pInstrumentGroupPopup->GetSubMenu(SubMenuGroup); pMenuInstruments->CheckMenuItem (SubItem, MF_CHECKED|MF_BYPOSITION); } void CPitchDlg::UpdatePort(int MyPort) { CMenu* pTopLevelPopup = menu.GetSubMenu(0); CMenu* pPortPopup = pTopLevelPopup->GetSubMenu(2); int i; // Uncheck all boxes for (i = 0; i < 4; i++) {pPortPopup->CheckMenuItem(i,MF_UNCHECKED| MF_BYPOSITION);}; // Now check the one the user ticked pPortPopup->CheckMenuItem (MyPort, MF_CHECKED|MF_BYPOSITION); // Close the midi port that is open and then open the requested port UResult = midiOutClose(hMidiOut); ShowError(); // wDeviceID = mciOpenParms.wDeviceID; wDeviceID = MyPort; UResult = midiOutOpen(&hMidiOut,wDeviceID, NULL,NULL,CALLBACK_NULL); } void CPitchDlg::OnClickMainTitle() { // Show dithered picture when pressed } void CPitchDlg::OnMainPopupNoteLength100() { NoteWaitTimeLength = 100; UpdateNoteLength(0); } void CPitchDlg::OnMainPopupNoteLength250() { NoteWaitTimeLength = 250; UpdateNoteLength(1); } void CPitchDlg::OnMainPopupNoteLength500() { NoteWaitTimeLength = 500; UpdateNoteLength(2); } void CPitchDlg::OnMainPopupNoteLength750() { NoteWaitTimeLength = 750; UpdateNoteLength(3); } void CPitchDlg::OnMainPopupNoteLength1000() { NoteWaitTimeLength = 1000; UpdateNoteLength(4); } void CPitchDlg::OnMainPopupNoteLength1500() { NoteWaitTimeLength = 1500; UpdateNoteLength(5); } void CPitchDlg::OnMainPopupNoteLength2000() { NoteWaitTimeLength = 2000; UpdateNoteLength(6); } void CPitchDlg::OnMainPopupNoteLength3000() { NoteWaitTimeLength = 3000; UpdateNoteLength(7); } void CPitchDlg::OnMainPopupNoteLength4000() { NoteWaitTimeLength = 4000; UpdateNoteLength(8); } void CPitchDlg::OnMainPopupNoteLength5000() { NoteWaitTimeLength = 5000; UpdateNoteLength(9); } void CPitchDlg::UpdateNoteLength(int MyNoteLength) { CMenu* pTopLevelPopup = menu.GetSubMenu(0); CMenu* pNoteLengthPopup = pTopLevelPopup->GetSubMenu(3); int i; // Uncheck all boxes for (i = 0; i < 10; i++) {pNoteLengthPopup->CheckMenuItem(i,MF_UNCHECKED| MF_BYPOSITION);}; // Now check the one the user ticked pNoteLengthPopup->CheckMenuItem (MyNoteLength, MF_CHECKED|MF_BYPOSITION); NoteLength = MyNoteLength; // This will be saved in registry } HBRUSH CPitchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // if (nCtlColor == CTLCOLOR_EDIT) // { // pDC->SetBkColor(YellowColour); // //return m_hYellowBrush; // return hbr; // } // if (nCtlColor == CTLCOLOR_DLG) // { // pDC->SetBkColor(YellowColour); // //return m_hRedBrush; // return hbr; // } // pDC->SetBkColor(YellowColour); // TODO: Return a different brush if the default is not desired return hbr; } void CPitchDlg::OnDestroy() { WinHelp(0L, HELP_QUIT); CDialog::OnDestroy(); // Grab the screen location at end for the registry //NormalizeRect(); CRect rect; CPoint TL; GetWindowRect(&rect); TL = rect.TopLeft(); MainX = TL.x; MainY = TL.y; rect.NormalizeRect(); MainWidth = rect.Width(); MainHeight = rect.Height(); // Close shop UResult = midiOutReset(hMidiOut); ShowError(); UResult = midiOutClose(hMidiOut); ShowError(); } void CPitchDlg::ShowError() { if (UResult != 0) {midiOutGetErrorText(UResult, strError, PLAY_BUFFER_LENGTH); MessageBox(strError);} } void CPitchDlg::SendShortMessage() { DWORD dwMsg; dwMsg = MAKEMIDISHORTMSG(bStatus, bChannel, bData1, bData2); UResult = midiOutShortMsg(hMidiOut,dwMsg); ShowError(); } void CPitchDlg::OnShowPreferences() { CPreferences dlg; dlg.DoModal(); } void CPitchDlg::OnHelpCommand() { // TODO: Add your control notification handler code here } void CPitchDlg::OnPitchTitle() { // TODO: Add your control notification handler code here }