www.pudn.com > EndpointDetection_Pitch.zip > Pitch.cpp


// Pitch.cpp : Defines the class behaviors for the application. 
// 
#include "stdafx.h" 
#include "Pitch.h" 
#include "PitchDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
                                           
char PurpleKey[27] = "Purple Note Software"; 
int MainX, MainY, MainWidth, MainHeight; 
extern int MainX, MainY, MainWidth, MainHeight; 
int  PerfectX, PerfectY, PerfectWidth, PerfectHeight; 
extern int PerfectX, PerfectY, PerfectWidth, PerfectHeight; 
int  RelativeX, RelativeY, RelativeWidth, RelativeHeight; 
extern int RelativeX, RelativeY, RelativeWidth, RelativeHeight; 
int ChordX, ChordY, ChordWidth, ChordHeight; 
extern int ChordX, ChordY, ChordWidth, ChordHeight; 
UINT DefaultMainX= 40, DefaultMainY=100, DefaultMainWidth=475, DefaultMainHeight=400; 
UINT DefaultPerfectX= 45, DefaultPerfectY=75, DefaultPerfectWidth=525, DefaultPerfectHeight=430; 
UINT DefaultRelativeX=5, DefaultRelativeY=5, DefaultRelativeWidth=600, DefaultRelativeHeight=550; 
UINT DefaultChordX=5, DefaultChordY=5, DefaultChordWidth=600, DefaultChordHeight=500; 
BYTE DefaultInstrument = 0; 
int  DefaultNoteLength = 15; 
int  DefaultPort = 0; 
extern int PreferencesPrompt; 
int PreferencesPrompt; 
extern BYTE InstrumentNumber; 
BYTE InstrumentNumber = 1; // default to 1st instrument 
extern int NoteLength; 
int NoteLength = 15; // Default to longest timeframe  
extern UINT PreferencesPort; 
UINT PreferencesPort; 
///////////////////////////////////////////////////////////////////////////// 
// CPitchApp 
 
BEGIN_MESSAGE_MAP(CPitchApp, CWinApp) 
	//{{AFX_MSG_MAP(CPitchApp) 
	//}}AFX_MSG_MAP 
	ON_COMMAND(ID_HELP, CWinApp::OnHelp) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPitchApp construction 
 
CPitchApp::CPitchApp() 
{ 
	// TODO: add construction code here, 
	// Place all significant initialization in InitInstance 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// The one and only CPitchApp object 
 
CPitchApp theApp; 
 
///////////////////////////////////////////////////////////////////////////// 
// CPitchApp initialization 
 
BOOL CPitchApp::InitInstance() 
{ 
	AfxEnableControlContainer(); 
 
	// Standard initialization 
 
	Enable3dControls();			// Call this when using MFC in a shared DLL 
	SetDialogBkColor(Grey2Colour,BlackColour); 
    // Load ini settings 
	SetRegistryKey(PurpleKey); 
UINT UResult; 
    UResult = GetProfileInt("Metrics","Main X",DefaultMainX); 
    MainX = UResult; 
	UResult = GetProfileInt("Metrics","Main Y",DefaultMainY); 
    MainY = UResult; 
    UResult = GetProfileInt("Metrics","Main Width",DefaultMainWidth); 
    MainWidth = UResult; 
	UResult = GetProfileInt("Metrics","Main Height",DefaultMainHeight); 
    MainHeight = UResult; 
	UResult = GetProfileInt("Metrics","Perfect X",DefaultPerfectX); 
    PerfectX = UResult; 
	UResult = GetProfileInt("Metrics","Perfect Y",DefaultPerfectY); 
    PerfectY = UResult; 
	UResult = GetProfileInt("Metrics","Perfect Width",DefaultPerfectWidth); 
    PerfectWidth = UResult; 
	UResult = GetProfileInt("Metrics","Perfect Height",DefaultPerfectHeight); 
	if (UResult < DefaultPerfectHeight)   // Don't allow any more shrinkage 
		{UResult = DefaultPerfectHeight;} // 
    PerfectHeight = UResult; 
	UResult = GetProfileInt("Metrics","Relative X",DefaultRelativeX); 
    RelativeX = UResult; 
	UResult = GetProfileInt("Metrics","Relative Y",DefaultRelativeY); 
	RelativeY = UResult; 
	UResult = GetProfileInt("Metrics","Relative Width",DefaultRelativeWidth); 
    RelativeWidth = UResult; 
	UResult = GetProfileInt("Metrics","Relative Height",DefaultRelativeHeight); 
	RelativeHeight = UResult; 
	//Chords 
	UResult = GetProfileInt("Metrics","Chord X",DefaultChordX); 
    ChordX = UResult; 
	UResult = GetProfileInt("Metrics","Chord Y",DefaultChordY); 
	ChordY = UResult; 
	UResult = GetProfileInt("Metrics","Chord Width",DefaultChordWidth); 
    ChordWidth = UResult; 
	UResult = GetProfileInt("Metrics","Chord Height",DefaultChordHeight); 
	ChordHeight = UResult; 
 
	UResult = GetProfileInt("Preferences","Prompt",0); 
	PreferencesPrompt = UResult; 
	UResult = GetProfileInt("Preferences","Instrument",DefaultInstrument); 
	InstrumentNumber = UResult; 
	UResult = GetProfileInt("Preferences","NoteLength",DefaultNoteLength); 
	NoteLength = UResult; 
	UResult = GetProfileInt("Preferences","Port",DefaultPort); 
	PreferencesPort = UResult; 
 
	// Play it safe as zero width or height leaves a ghost 
	if (MainWidth == 0) {MainWidth = DefaultMainWidth;}; 
	if (MainHeight == 0) {MainHeight = DefaultMainHeight;}; 
	if (PerfectWidth == 0) {PerfectWidth = DefaultPerfectWidth;}; 
	if (PerfectHeight == 0) {PerfectHeight = DefaultPerfectHeight;}; 
	if (RelativeWidth == 0) {RelativeWidth = DefaultRelativeWidth;}; 
	if (RelativeHeight == 0) {RelativeHeight = DefaultRelativeHeight;}; 
	if (ChordWidth == 0) {ChordWidth = DefaultChordWidth;}; 
	if (ChordHeight == 0) {ChordHeight = DefaultChordHeight;}; 
	// Set height and width here for testing 
	//MainWidth = 475; 
	//MainHeight = 400; 
	//PerfectWidth = 525; 
	//PerfectHeight = 430; 
	//RelativeWidth = 600; 
	//RelativeHeight = 550; 
	//ChordWidth = 600; 
	//ChordHeight = 500; 
	 
	CPitchDlg dlg; 
	m_pMainWnd = &dlg; 
	int nResponse = dlg.DoModal(); 
	if (nResponse == IDOK) 
	{ 
		// Update key so user starts the same way next time 
		WriteProfileInt("Metrics","Main X",MainX); 
		WriteProfileInt("Metrics","Main Y",MainY); 
		WriteProfileInt("Metrics","Main Width",MainWidth); 
		WriteProfileInt("Metrics","Main Height",MainHeight); 
		WriteProfileInt("Metrics","Perfect X",PerfectX); 
		WriteProfileInt("Metrics","Perfect Y",PerfectY); 
		WriteProfileInt("Metrics","Perfect Width",PerfectWidth); 
		WriteProfileInt("Metrics","Perfect Height",PerfectHeight); 
		WriteProfileInt("Metrics","Relative X",RelativeX); 
		WriteProfileInt("Metrics","Relative Y",RelativeY); 
		WriteProfileInt("Metrics","Relative Width",RelativeWidth); 
		WriteProfileInt("Metrics","Relative Height",RelativeHeight); 
		WriteProfileInt("Metrics","Chord X",ChordX); 
		WriteProfileInt("Metrics","Chord Y",ChordY); 
		WriteProfileInt("Metrics","Chord Width",ChordWidth); 
		WriteProfileInt("Metrics","Chord Height",ChordHeight); 
		WriteProfileInt("Preferences","Prompt",PreferencesPrompt); 
		WriteProfileInt("Preferences","Instrument",InstrumentNumber); 
		WriteProfileInt("Preferences","NoteLength",NoteLength); 
 
	} 
	else if (nResponse == IDCANCEL) 
	{ 
		// TODO: Place code here to handle when the dialog is 
		//  dismissed with Cancel 
	} 
 
	// Since the dialog has been closed, return FALSE so that we exit the 
	//  application, rather than start the application's message pump. 
	return FALSE; 
}