// --------------------------------------------------------------------------- #include #pragma hdrstop #include #include "GlobalUnit.h" #include "CommonUnit.h" // #include "ComposeStage.h" // --------------------------------------------------------------------------- #pragma package(smart_init) #include #pragma comment(lib, "iphlpapi.lib") #define EX_NULL = NULL /*************************************************************************************** / // 全局常量 /************************************************************************************** */ const char *g_strDefaultSoundSet = "Pop default", *g_strSoundSetExt = "SF2", *g_strMelodyKey[KEY_NUM] = { "C", "bD", "D", "bE", "E", "F", "#F", "G", "bA", "A", "bB", "B"}, // 调号显示 *g_strTimeSignature[4] = {"4/4", "3/4", "2/4", "6/8"}, // 拍号 *g_strTSName[4] = {"44", "43", "42", "86"}, // 拍号命名 *g_strIntro[MAX_INTRO_NUM] = {"前/间奏-1", "前/间奏-2", "前/间奏-3", "前/间奏-4" }, // 插入段显示文字 *g_strEnding[MAX_ENDING_NUM] = {"尾奏-1", "尾奏-2", "尾奏-3", "尾奏-4" }, *g_strFill[COMPOSE_FILL_NUM] = {"加花-1", "加花-2"}, // 加花小节显示文字 *g_strStage = "%c段", // 旋律段显示文字 *g_strStageVar[STAGE_VAR_NUM] = {"(伴奏型1)", "(伴奏型2)", "(伴奏型3)", "(伴奏型4)" }, // 分段伴奏型文字 *g_strProjError[10] = { "打开工程失败!\n\n文件不存在", "打开工程失败!\n\n版本太新,请更新软件到最新版", "打开工程失败!\n\n专业版工程,请尝试用专业版打开", "打开工程失败!\n\n无法识别的版本号", "打开工程失败!\n\n文件已损坏", "打开工程失败!\n\n音频数据被破环", "打开工程失败!\n\n使用的风格未下载或已失效", "指定音色库失效,使用缺省音色库。", "部分段落风格失效,使用全局风格替换。" }; const COLORREF g_clrBackground = RGB(225, 225, 225), // 背景颜色, g_clrGrid = RGB(127, 127, 127), // 格子颜色 g_clrText = RGB(0, 0, 0), // 文字颜色 g_clrChordBk = RGB(255, 255, 255), // 和弦背景色 g_clrFocus = RGB(227, 24, 19), // 选中颜色 g_clrPlayLine = RGB(255, 0, 0), // 播放标示线 g_clrStage[STAGE_VAR_NUM] = { RGB(255, 240, 200), RGB(252, 236, 174), RGB(241, 205, 143), RGB(242, 185, 121)}, // 分段颜色 g_clrStageDisable[STAGE_VAR_NUM] = { RGB(206, 194, 162), RGB(204, 191, 141), RGB(195, 166, 116), RGB(195, 149, 98)}, // 禁用分段颜色 g_clrEnding[MAX_INTRO_NUM] = { RGB(203, 219, 247), RGB(190, 206, 233), RGB(200, 200, 200), RGB(192, 192, 192)}, g_clrEndingDisable[MAX_INTRO_NUM] = { RGB(164, 177, 200), RGB(153, 166, 188), RGB(200, 200, 200), RGB(192, 192, 192)}, g_clrIntro[MAX_ENDING_NUM] = { RGB(196, 230, 147), RGB(179, 215, 176), RGB(164, 164, 164), RGB(156, 156, 156)}, g_clrIntroDisable[MAX_ENDING_NUM] = { RGB(158, 186, 119), RGB(145, 174, 142), RGB(164, 164, 164), RGB(156, 156, 156)}; const DWORD g_dwProjectVersion = MAKELONG(8, 2); //ver 2.8 //ver 2.0-2.1禁用,以判断早期版本 //ver 2.4 支持midimelody //ver 2.5 g_bPredefine读写,支持无Audio //ver 2.6 风格支付记/录记录工程功能费支付 //ver 2.7 增加工程模式标志 iMode=0,1,2 //ver 2.8 UPLOAD工程不写入声波数据 /*************************************************************************************** / // 全局变量 /************************************************************************************** */ FONTINFOLIST g_lstFonts; // 音色库列表 MELODYBARLIST g_lstMelodyBars, // 旋律小节信息 g_lstMelodyBars_SVD; MELODYSTAGELIST g_lstMelodyStages, // 旋律分段 g_lstMelodyStages_SVD; COMPOSESTAGELIST g_lstComposeStages, // 曲式结构段落表 g_lstComposeStages_SVD; BARVOLSLIST g_lstCompleteVols, // 全曲音波表 g_lstCompleteVols_SVD; wstring g_strFontPath, // 音色库路径 g_strFontFile, // 音色库文件名 g_strFontFile_SVD, // 音色库文件名(已保存) g_strLastSaveFile, // 上次保存音乐文件名 g_strExecutePath, // 执行文件路径 g_strUserPath, // 用户路径 g_strExtFontsPath, //扩展音色库路径 g_strProjectName, // 工程文件名 g_strAutoProjName; // 自动保存文件名 vectorg_lstRecentProject; // 最近的工程文件 HANDLE g_hProjectEvent; // 工程文件读写互斥变量 string g_strSelectedStyleName; // 选中风格名 vectorg_lstStyleSelected; // 选中风格类型集合 DWORD g_iSelectedStyleType = 0; // 选定风格类型 char g_strCurrentVersion[20] = "", g_strServerURL[256] = "", g_strPlaybackDevice[256] = "", g_strRecordDevice[256] = ""; int g_arrIntroBarNum[MAX_INTRO_NUM], // 全局风格前间奏小节数 g_arrEndingBarNum[MAX_ENDING_NUM], // 全局风格尾奏小节数 g_idFont = -1, // 选中音色库序号 g_iSelectedStyleID = -1, // 风格ID g_iLastStyleID = -1, // 上次使用的风格 g_iMelodyKey = -1, // 主旋律调号 g_iComposeKey = -1, // 伴奏调号,用于录音升降调 g_iMelodyTimeSignature = 0, // 主旋律拍号 g_nMelodyTempo = 75, // 主旋律速度 g_iPlaybackDevice = -1, // 指定播放设备号 g_iPlaybackOutput = -1, // 指定播放输出源 g_iRecordDevice = -1, //指定录音设备号 g_iRecordInput = -1, //录音输入源 g_nRecordChannels = 1, //缺省单通道录音 // g_lSongParam = 0, // 全曲参数 // g_lSongVerifyParam = 0, // 全曲鉴权参数 g_iLastSaveOption = SAVE_COMPOSESONG, // 上次保存选项 g_iLastSaveType = FILETYPE_MP3, // 上次保存文件格式 g_iCurrentPage = -1, // 保存工程时所处的页面 g_iWindowState = wsNormal, g_iPreStageDefault = 2, g_iPreStyleSort = STYLESORT_TIME | (STYLESORT_UP<<16), g_nBuildVersion, g_iSelectedStyleID_SVD = -1, g_iComposeKey_SVD = -1, g_iMelodyKey_SVD = -1, // 主旋律调号(已保存) g_iMelodyTimeSignature_SVD = 0, // 主旋律拍号(已保存) g_nMelodyTempo_SVD = 75; // 主旋律速度(已保存) float g_fRecordVolume = -1, // 录音音量 g_fSpeakerVolume = -1, // 喇叭音量 g_fAudioVolume = 1, // 音频音量 g_fMusicVolume = 1, // 伴奏音量 g_fRecordVolume_SVD = -1, g_fSpeakerVolume_SVD = -1, g_fAudioVolume_SVD = 1, g_fMusicVolume_SVD = 1; double g_dblStep = 0, g_dblTimePerBar = 0; TUSERINFO g_infoUser; TSOFTWAREINFO g_infoSoftwareUpdate; TSONGINFO g_infoSong; bool g_bRecordAutoAdjust = true, //录音自动音量调节 g_bRecordMoniter = false, //不启用录音监听 g_bShowRecordHint = true, // 噪音侦测 g_bUpdateMandatory = false, // 客户端需要强制更新 g_bMidiMelody = false, //导入MIDI旋律 g_bWeakup = false, // 旋律弱起 g_bShowPlayTick = true, // 显示小节节拍或时间 g_bAutoLogin = true, g_bLogon = false, g_bRecProtect = false, // 内录保护 g_bShowProtectMsg = true, //显示内录保护消息 g_bPredefine = false, // 预设工程(不自动编曲/接唱) g_bAudioLoaded = false, // 音频已加载 g_bBaseComposeLoaded = false, // 基本编曲已加载 g_bComposeLoaded = false, // 编曲已加载 g_bSongLoaded = false, // 全曲已加载 // g_bSongSaved = false, //全曲已保存 g_bAudioChanged = false, // 初始录音修改 g_bSongChanged = false, // 全曲录音修改 g_bSongNeedSave = false, // 全曲录音需保存 g_bAutoSave = false, //是否需要恢复工程 //add by tj 2013/12/30 g_bAutoDownloadStyle = true, //自动下载风格 g_bAutoOpenProject = false, //自动打开上次工程 g_bAutoOpenProjectEnable = false, //自动打开上次工程使能 g_bProjStylePaid = false, //工程风格支付更改 g_iShowType = false, // false,罗马,true,英文 g_bPrebeat = false, //使用预设风格节拍提示 g_bExtFontUsable = false, //扩展音色库可用 g_bExtFont = false, //使用扩展音色库 g_bCanStep = false; int g_aAudioEffects[MAX_FX_NUM], //启用的音效 g_aAudioEffects_SVD[MAX_FX_NUM]; DWORD g_aAudioEffectTypes[MAX_FX_NUM]; //音效类型 //DWORD g_iMacAddressNum = 0; //mac地址个数 vector g_lstMacAddress; //mac地址 //vector g_lstMacAddressNew; String g_strMP3File; //mp3全曲文件名 UINT g_xDpi=96, g_yDpi=96; //High DPI 自适应 int g_szFont8 = 8, g_szFont9 = 9, g_szFont16 = 16; /*************************************************************************************** / // 全局函数声明 /************************************************************************************** */ SM_GetVersion f_SM_GetVersion EX_NULL; SM_Initialize f_SM_Initialize EX_NULL; SM_Release f_SM_Release EX_NULL; SM_CheckStyle f_SM_CheckStyle EX_NULL; SM_GetSegmentBarNum f_SM_GetSegmentBarNum EX_NULL; SM_GetStyleRecomInfos f_SM_GetStyleRecomInfos EX_NULL; SM_GetStyleDemo f_SM_GetStyleDemo EX_NULL; SM_GetStyleInfo f_SM_GetStyleInfo EX_NULL; SM_GetStyleInfos f_SM_GetStyleInfos EX_NULL; SM_InputWavNotes f_SM_InputWavNotes EX_NULL; SM_BaseCompose f_SM_BaseCompose EX_NULL; SM_Compose f_SM_Compose EX_NULL; SM_GetPrebeat f_SM_GetPrebeat EX_NULL; MM_GetVersion f_MM_GetVersion EX_NULL; MM_InitialObjects f_MM_InitialObjects EX_NULL; MM_DestroyObjects f_MM_DestroyObjects EX_NULL; MM_GetFontInfo f_MM_GetFontInfo EX_NULL; MM_CheckExtFont f_MM_CheckExtFont EX_NULL; MM_SetFont f_MM_SetFont EX_NULL; MM_Record f_MM_Record EX_NULL; MM_LoadMidiMelody f_MM_LoadMidiMelody EX_NULL; MM_LoadBaseCompose f_MM_LoadBaseCompose EX_NULL; MM_LoadCompose f_MM_LoadCompose EX_NULL; MM_LoadPrebeat f_MM_LoadPrebeat EX_NULL; MM_Play f_MM_Play EX_NULL; MM_Stop f_MM_Stop EX_NULL; MM_CheckIODevice f_MM_CheckIODevice EX_NULL; MM_SetIODevice f_MM_SetIODevice EX_NULL; MM_GetPlaybackDeviceInfo f_MM_GetPlaybackDeviceInfo EX_NULL; MM_GetPlaybackOutputInfo f_MM_GetPlaybackOutputInfo EX_NULL; MM_GetRecordDeviceInfo f_MM_GetRecordDeviceInfo EX_NULL; MM_GetRecordInputInfo f_MM_GetRecordInputInfo EX_NULL; MM_RecordTest f_MM_RecordTest EX_NULL; MM_SetRecordAutoAdjust f_MM_SetRecordAutoAdjust EX_NULL; MM_SetRecordMoniter f_MM_SetRecordMoniter EX_NULL; MM_SetRecordProtect f_MM_SetRecordProtect EX_NULL; MM_ShowAsioPanel f_MM_ShowAsioPanel EX_NULL; MM_RestartAsioDevice f_MM_RestartAsioDevice EX_NULL; MM_LoadAudio f_MM_LoadAudio EX_NULL; MM_ClearAudio f_MM_ClearAudio EX_NULL; MM_GetMelodyInfo f_MM_GetMelodyInfo EX_NULL; MM_GetMelody f_MM_GetMelody EX_NULL; MM_CreateRealTimeMIDIStream f_MM_CreateRealTimeMIDIStream EX_NULL; MM_FreeRealTimeMIDIStream f_MM_FreeRealTimeMIDIStream EX_NULL; MM_RealTimeMIDINoteOn f_MM_RealTimeMIDINoteOn EX_NULL; MM_RealTimeMIDINoteOff f_MM_RealTimeMIDINoteOff EX_NULL; MM_PlayStyleDemo f_MM_PlayStyleDemo EX_NULL; MM_SetTempo f_MM_SetTempo EX_NULL; MM_SetTimeSignature f_MM_SetTimeSignature EX_NULL; MM_GetAudioVolume f_MM_GetAudioVolume EX_NULL; MM_GetStreamVolume f_MM_GetStreamVolume EX_NULL; MM_SetStreamVolume f_MM_SetStreamVolume EX_NULL; MM_GetLatency f_MM_GetLatency EX_NULL; MM_GetStreamLength f_MM_GetStreamLength EX_NULL; MM_SetStreamLength f_MM_SetStreamLength EX_NULL; MM_CombineSong f_MM_CombineSong EX_NULL; MM_Save f_MM_Save EX_NULL; MM_SaveProject f_MM_SaveProject EX_NULL; MM_LoadProject f_MM_LoadProject EX_NULL; MM_UserCanceled f_MM_UserCanceled EX_NULL; MM_LoadAnalysis f_MM_LoadAnalysis EX_NULL; MM_LoadAudioMP3 f_MM_LoadAudioMP3 EX_NULL; MM_LoadSongMP3 f_MM_LoadSongMP3 EX_NULL; MM_ActiveAPR f_MM_ActiveAPR EX_NULL; MM_SetFxPreset f_MM_SetFxPreset EX_NULL; CS_GetVersion f_CS_GetVersion EX_NULL; CS_InitialService f_CS_InitialService EX_NULL; CS_DestroyService f_CS_DestroyService EX_NULL; CS_Register f_CS_Register EX_NULL; CS_Login f_CS_Login EX_NULL; CS_Logoff f_CS_Logoff EX_NULL; CS_CancelOperation f_CS_CancelOperation EX_NULL; CS_DownloadStyle f_CS_DownloadStyle EX_NULL; CS_GetQnA f_CS_GetQnA EX_NULL; CS_SubmitQnA f_CS_SubmitQnA EX_NULL; CS_GetNotice f_CS_GetNotice EX_NULL; CS_GetNewNoticeNum f_CS_GetNewNoticeNum EX_NULL; CS_UploadSong f_CS_UploadSong EX_NULL; CS_GetWebPageURL f_CS_GetWebPageURL EX_NULL; CS_GetStyleNums f_CS_GetStyleNums EX_NULL; CS_CheckPayment f_CS_CheckPayment EX_NULL; CS_ConfirmPayment f_CS_ConfirmPayment EX_NULL; CS_AutoDownloadStyle f_CS_AutoDownloadStyle EX_NULL; CS_SaveProject f_CS_SaveProject EX_NULL; CS_LoadProject f_CS_LoadProject EX_NULL; CS_ResetProject f_CS_ResetProject EX_NULL; QR_Encode f_QR_Encode EX_NULL; /*************************************************************************************** / // 全局函数实现 /************************************************************************************** */ HRESULT GetMFFunctions(HINSTANCE hDll) { // VERIFY( hDll ); f_SM_GetVersion = (SM_GetVersion)GetProcAddress(hDll, "SM_GetVersion"); f_SM_Initialize = (SM_Initialize)GetProcAddress(hDll, "SM_Initialize"); f_SM_Release = (SM_Release)GetProcAddress(hDll, "SM_Release"); f_SM_CheckStyle = (SM_CheckStyle)GetProcAddress(hDll, "SM_CheckStyle"); f_SM_GetSegmentBarNum = (SM_GetSegmentBarNum)GetProcAddress(hDll, "SM_GetSegmentBarNum"); f_SM_GetStyleRecomInfos = (SM_GetStyleRecomInfos)GetProcAddress(hDll, "SM_GetStyleRecomInfos"); f_SM_GetStyleDemo = (SM_GetStyleDemo)GetProcAddress(hDll, "SM_GetStyleDemo"); f_SM_GetStyleInfo = (SM_GetStyleInfo)GetProcAddress(hDll, "SM_GetStyleInfo"); f_SM_GetStyleInfos = (SM_GetStyleInfos)GetProcAddress(hDll, "SM_GetStyleInfos"); f_SM_InputWavNotes = (SM_InputWavNotes)GetProcAddress(hDll, "SM_InputWavNotes"); f_SM_BaseCompose = (SM_BaseCompose)GetProcAddress(hDll, "SM_BaseCompose"); f_SM_Compose = (SM_Compose)GetProcAddress(hDll, "SM_Compose"); f_SM_GetPrebeat = (SM_GetPrebeat)GetProcAddress(hDll, "SM_GetPrebeat"); if (!(f_SM_Initialize && f_SM_Release && f_SM_CheckStyle && f_SM_GetVersion && f_SM_GetSegmentBarNum && f_SM_GetStyleRecomInfos && f_SM_GetStyleDemo && f_SM_InputWavNotes && f_SM_BaseCompose && f_SM_Compose && f_SM_GetStyleInfo && f_SM_GetStyleInfos && f_SM_GetPrebeat )){ return S_FALSE; } HRESULT hr = f_SM_GetVersion(); if( hr!=SM_VERSION || f_SM_Initialize()!= S_OK ){ return S_FALSE; } return S_OK; } HRESULT GetMMFunctions(HINSTANCE hDll) { // VERIFY( hDll ); f_MM_GetVersion = (MM_GetVersion)GetProcAddress(hDll, "MM_GetVersion"); f_MM_InitialObjects = (MM_InitialObjects)GetProcAddress(hDll, "MM_InitialObjects"); f_MM_DestroyObjects = (MM_DestroyObjects)GetProcAddress(hDll, "MM_DestroyObjects"); f_MM_GetFontInfo = (MM_GetFontInfo)GetProcAddress(hDll, "MM_GetFontInfo"); f_MM_CheckExtFont = (MM_CheckExtFont)GetProcAddress(hDll, "MM_CheckExtFont"); f_MM_SetFont = (MM_SetFont)GetProcAddress(hDll, "MM_SetFont"); f_MM_Record = (MM_Record)GetProcAddress(hDll, "MM_Record"); f_MM_LoadMidiMelody = (MM_LoadMidiMelody)GetProcAddress(hDll, "MM_LoadMidiMelody"); f_MM_LoadBaseCompose = (MM_LoadBaseCompose)GetProcAddress(hDll, "MM_LoadBaseCompose"); f_MM_LoadCompose = (MM_LoadCompose)GetProcAddress(hDll, "MM_LoadCompose"); f_MM_LoadPrebeat = (MM_LoadPrebeat)GetProcAddress(hDll, "MM_LoadPrebeat"); f_MM_Play = (MM_Play)GetProcAddress(hDll, "MM_Play"); f_MM_Stop = (MM_Stop)GetProcAddress(hDll, "MM_Stop"); f_MM_CheckIODevice = (MM_CheckIODevice)GetProcAddress(hDll, "MM_CheckIODevice"); f_MM_SetIODevice = (MM_SetIODevice)GetProcAddress(hDll, "MM_SetIODevice"); f_MM_GetPlaybackDeviceInfo = (MM_GetPlaybackDeviceInfo)GetProcAddress(hDll, "MM_GetPlaybackDeviceInfo"); f_MM_GetPlaybackOutputInfo = (MM_GetPlaybackOutputInfo)GetProcAddress(hDll, "MM_GetPlaybackOutputInfo"); f_MM_GetRecordDeviceInfo = (MM_GetRecordDeviceInfo)GetProcAddress(hDll, "MM_GetRecordDeviceInfo"); f_MM_GetRecordInputInfo = (MM_GetRecordInputInfo)GetProcAddress(hDll, "MM_GetRecordInputInfo"); f_MM_RecordTest = (MM_RecordTest)GetProcAddress(hDll, "MM_RecordTest"); f_MM_SetRecordAutoAdjust = (MM_SetRecordAutoAdjust)GetProcAddress(hDll, "MM_SetRecordAutoAdjust"); f_MM_SetRecordMoniter = (MM_SetRecordMoniter)GetProcAddress(hDll, "MM_SetRecordMoniter"); f_MM_SetRecordProtect = (MM_SetRecordProtect)GetProcAddress(hDll, "MM_SetRecordProtect"); f_MM_ShowAsioPanel = (MM_ShowAsioPanel)GetProcAddress(hDll, "MM_ShowAsioPanel"); f_MM_RestartAsioDevice = (MM_RestartAsioDevice)GetProcAddress(hDll, "MM_RestartAsioDevice"); f_MM_LoadAudio = (MM_LoadAudio)GetProcAddress(hDll, "MM_LoadAudio"); f_MM_ClearAudio = (MM_ClearAudio)GetProcAddress(hDll, "MM_ClearAudio"); f_MM_GetMelodyInfo = (MM_GetMelodyInfo)GetProcAddress(hDll, "MM_GetMelodyInfo"); f_MM_GetMelody = (MM_GetMelody)GetProcAddress(hDll, "MM_GetMelody"); f_MM_CreateRealTimeMIDIStream = (MM_CreateRealTimeMIDIStream)GetProcAddress(hDll, "MM_CreateRealTimeMIDIStream"); f_MM_FreeRealTimeMIDIStream = (MM_FreeRealTimeMIDIStream)GetProcAddress(hDll, "MM_FreeRealTimeMIDIStream"); f_MM_RealTimeMIDINoteOn = (MM_RealTimeMIDINoteOn)GetProcAddress(hDll, "MM_RealTimeMIDINoteOn"); f_MM_RealTimeMIDINoteOff = (MM_RealTimeMIDINoteOff)GetProcAddress(hDll, "MM_RealTimeMIDINoteOff"); f_MM_PlayStyleDemo = (MM_PlayStyleDemo)GetProcAddress(hDll, "MM_PlayStyleDemo"); f_MM_SetTempo = (MM_SetTempo)GetProcAddress(hDll, "MM_SetTempo"); f_MM_SetTimeSignature = (MM_SetTimeSignature)GetProcAddress(hDll, "MM_SetTimeSignature"); f_MM_GetAudioVolume = (MM_GetAudioVolume)GetProcAddress(hDll, "MM_GetAudioVolume"); f_MM_GetStreamVolume = (MM_GetStreamVolume)GetProcAddress(hDll, "MM_GetStreamVolume"); f_MM_SetStreamVolume = (MM_SetStreamVolume)GetProcAddress(hDll, "MM_SetStreamVolume"); f_MM_GetLatency = (MM_GetLatency)GetProcAddress(hDll, "MM_GetLatency"); f_MM_GetStreamLength = (MM_GetStreamLength)GetProcAddress(hDll, "MM_GetStreamLength"); f_MM_SetStreamLength = (MM_SetStreamLength)GetProcAddress(hDll, "MM_SetStreamLength"); f_MM_CombineSong = (MM_CombineSong)GetProcAddress(hDll, "MM_CombineSong"); f_MM_Save = (MM_Save)GetProcAddress(hDll, "MM_Save"); f_MM_UserCanceled = (MM_UserCanceled)GetProcAddress(hDll, "MM_UserCanceled"); f_MM_SaveProject = (MM_SaveProject)GetProcAddress(hDll, "MM_SaveProject"); f_MM_LoadProject = (MM_LoadProject)GetProcAddress(hDll, "MM_LoadProject"); f_MM_LoadAnalysis = (MM_LoadAnalysis)GetProcAddress(hDll, "MM_LoadAnalysis"); f_MM_LoadAudioMP3 = (MM_LoadAudioMP3)GetProcAddress(hDll, "MM_LoadAudioMP3"); f_MM_LoadSongMP3 = (MM_LoadSongMP3)GetProcAddress(hDll, "MM_LoadSongMP3"); f_MM_ActiveAPR = (MM_ActiveAPR)GetProcAddress(hDll, "MM_ActiveAPR"); f_MM_SetFxPreset = (MM_SetFxPreset)GetProcAddress(hDll, "MM_SetFxPreset"); if (!(f_MM_InitialObjects && f_MM_DestroyObjects && f_MM_GetFontInfo && f_MM_SetFont && f_MM_LoadMidiMelody && f_MM_LoadBaseCompose && f_MM_LoadCompose && f_MM_ClearAudio && f_MM_LoadAudio && f_MM_Record && f_MM_Play && f_MM_Stop && f_MM_CombineSong && f_MM_Save && f_MM_UserCanceled && f_MM_GetMelodyInfo && f_MM_GetMelody && f_MM_CreateRealTimeMIDIStream && f_MM_FreeRealTimeMIDIStream && f_MM_CheckExtFont && f_MM_RealTimeMIDINoteOn && f_MM_RealTimeMIDINoteOff && f_MM_SetRecordMoniter && f_MM_PlayStyleDemo && f_MM_SetTempo && f_MM_SetTimeSignature && f_MM_LoadPrebeat && f_MM_SetFxPreset && f_MM_ActiveAPR && f_MM_GetStreamLength && f_MM_GetAudioVolume && f_MM_GetStreamLength && f_MM_GetStreamVolume && f_MM_SetStreamVolume && f_MM_SaveProject && f_MM_LoadProject && f_MM_GetLatency && f_MM_RestartAsioDevice && f_MM_LoadAnalysis && f_MM_LoadAudioMP3 && f_MM_LoadSongMP3 && f_MM_CheckIODevice && f_MM_SetIODevice && f_MM_GetPlaybackDeviceInfo && f_MM_GetPlaybackOutputInfo && f_MM_GetRecordDeviceInfo && f_MM_GetRecordInputInfo && f_MM_RecordTest && f_MM_SetRecordAutoAdjust && f_MM_SetRecordProtect && f_MM_ShowAsioPanel && f_MM_GetVersion )) { return S_FALSE; } return S_OK; } HRESULT GetCSFunctions(HINSTANCE hDll) { // VERIFY( hDll ); f_CS_GetVersion = (CS_GetVersion)GetProcAddress(hDll, "CS_GetVersion"); f_CS_InitialService = (CS_InitialService)GetProcAddress(hDll,"CS_InitialService"); f_CS_DestroyService = (CS_DestroyService)GetProcAddress(hDll,"CS_DestroyService"); f_CS_Register = (CS_Register)GetProcAddress(hDll, "CS_Register"); f_CS_Login = (CS_Login)GetProcAddress(hDll, "CS_Login"); f_CS_Logoff = (CS_Logoff)GetProcAddress(hDll, "CS_Logoff"); f_CS_CancelOperation = (CS_CancelOperation)GetProcAddress(hDll, "CS_CancelOperation"); f_CS_DownloadStyle = (CS_DownloadStyle)GetProcAddress(hDll, "CS_DownloadStyle"); f_CS_GetQnA = (CS_GetQnA)GetProcAddress(hDll, "CS_GetQnA"); f_CS_SubmitQnA = (CS_SubmitQnA)GetProcAddress(hDll, "CS_SubmitQnA"); f_CS_GetNotice = (CS_GetNotice)GetProcAddress(hDll, "CS_GetNotice"); f_CS_GetNewNoticeNum = (CS_GetNewNoticeNum)GetProcAddress(hDll, "CS_GetNewNoticeNum"); f_CS_UploadSong = (CS_UploadSong)GetProcAddress(hDll, "CS_UploadSong"); f_CS_GetWebPageURL = (CS_GetWebPageURL)GetProcAddress(hDll, "CS_GetWebPageURL"); f_CS_GetStyleNums = (CS_GetStyleNums)GetProcAddress(hDll, "CS_GetStyleNums"); f_CS_CheckPayment = (CS_CheckPayment)GetProcAddress(hDll, "CS_CheckPayment"); f_CS_ConfirmPayment = (CS_ConfirmPayment)GetProcAddress(hDll, "CS_ConfirmPayment"); f_CS_AutoDownloadStyle = (CS_AutoDownloadStyle)GetProcAddress(hDll, "CS_AutoDownloadStyle"); f_CS_SaveProject = (CS_SaveProject)GetProcAddress(hDll, "CS_SaveProject"); f_CS_LoadProject = (CS_LoadProject)GetProcAddress(hDll, "CS_LoadProject"); f_CS_ResetProject = (CS_ResetProject)GetProcAddress(hDll, "CS_ResetProject"); if (!(f_CS_InitialService && f_CS_DestroyService && f_CS_Login && f_CS_Login && f_CS_CancelOperation && f_CS_DownloadStyle && f_CS_GetQnA && f_CS_SubmitQnA && f_CS_Register && f_CS_UploadSong && f_CS_GetWebPageURL && f_CS_GetStyleNums && f_CS_GetNotice && f_CS_GetNewNoticeNum && f_CS_CheckPayment && f_CS_ConfirmPayment && f_CS_AutoDownloadStyle && f_CS_SaveProject && f_CS_LoadProject && f_CS_ResetProject && f_CS_GetVersion )) { return S_FALSE; } return S_OK; } HRESULT GetQRFunctions(HINSTANCE hDll) { f_QR_Encode = (QR_Encode)GetProcAddress(hDll, "QR_Encode"); return S_OK; } void SetMelodyTempo(int nTempo, bool bInit) { if (bInit || g_nMelodyTempo != nTempo) { int nBeatsPerMeasure; switch (g_iMelodyTimeSignature) { case 0: nBeatsPerMeasure = 4; break; case 1: nBeatsPerMeasure = 3; break; case 2: nBeatsPerMeasure = 2; break; case 3: nBeatsPerMeasure = 3; break; } g_dblStep = TIMER_PLAY_INTERVAL * POINTS_PER_BAR * (double)nTempo / (double)nBeatsPerMeasure / 60000.0; g_dblTimePerBar = (double)nBeatsPerMeasure * 60000.0 / nTempo; f_MM_SetTempo(nTempo); g_nMelodyTempo = nTempo; g_bProjStylePaid = false; } } void SetMelodyTS(int iTS, bool bInit) { if (bInit || g_iMelodyTimeSignature != iTS) { int nBeatsPerMeasure; switch (iTS) { case 0: nBeatsPerMeasure = 4; break; case 1: nBeatsPerMeasure = 3; break; case 2: nBeatsPerMeasure = 2; break; case 3: nBeatsPerMeasure = 3; break; } g_dblStep = TIMER_PLAY_INTERVAL * POINTS_PER_BAR * (double) g_nMelodyTempo / (double)nBeatsPerMeasure / 60000.0; g_dblTimePerBar = (double)nBeatsPerMeasure * 60000.0 / g_nMelodyTempo; g_iMelodyTimeSignature = iTS; f_MM_SetTimeSignature( g_iMelodyTimeSignature ); } } int ActiveAPR( bool bActive ) { if( f_MM_ActiveAPR ){ return f_MM_ActiveAPR( bActive ); } return S_FALSE; } void SetWavNotes() { int nNotesNum = f_MM_GetMelodyInfo(NULL, NULL, NULL); if (nNotesNum > 0) { BYTE *keys = new BYTE[nNotesNum]; WORD *delay = new WORD[nNotesNum]; f_MM_GetMelody(keys, delay, g_iMelodyKey); int nBarNum, nTick = 192;//(g_nMelodyTempo >= 125) ? 24 : (g_nMelodyTempo >= 83) ? 48 : 72; DebugPrint("MF_InputWaveNote"); f_SM_InputWavNotes(keys, delay, nNotesNum, nTick, (BYTE)g_iMelodyTimeSignature, g_nMelodyTempo, &nBarNum); // 计算弱起 int nBeatsPerMeasure; switch (g_iMelodyTimeSignature) { case 0: nBeatsPerMeasure = 4; break; case 1: nBeatsPerMeasure = 3; break; case 2: nBeatsPerMeasure = 2; break; case 3: nBeatsPerMeasure = 3; break; } g_bWeakup = nBarNum>1 && keys[0] == 128 && delay[0] > nTick * nBeatsPerMeasure / 2; delete[]keys; delete[]delay; } } void SetPlayTimer(bool bStart, UINT& tTimer, UINT& tAccuracy, void* pUser) { if (bStart) { // 打开定时器 // 设置定时器 TIMECAPS tc; MMRESULT mrError; // 利用函数timeGetDevCaps取出系统分辨率的取值范围,如果有错报错退出 memset(&tc, 0, sizeof(TIMECAPS)); mrError = timeGetDevCaps(&tc, sizeof(TIMECAPS)); if (!mrError == TIMERR_NOERROR) { DebugPrint("Get system accuracy failed! code = %x", mrError); } // 分辨率的值不能超出系统的取值范围 tAccuracy = tc.wPeriodMin > TIMER_ACCURACY ? tc.wPeriodMin : TIMER_ACCURACY; tAccuracy = tAccuracy < tc.wPeriodMax ? tAccuracy : tc.wPeriodMax; // 调用timeBeginPeriod函数设置定时器的分辨率 timeBeginPeriod(tAccuracy); tTimer = timeSetEvent(TIMER_PLAY_INTERVAL, tAccuracy, (LPTIMECALLBACK)OnMediaTimer, (DWORD_PTR)pUser, TIME_PERIODIC); } else { // 关闭定时器 timeKillEvent(tTimer); timeEndPeriod(tAccuracy); } } void GetPlayTime(int iStartBar, double dblStartPoint, char* strTime) { int nBeatsPerMeasure = (g_iMelodyTimeSignature == 0) ? 4 : (g_iMelodyTimeSignature == 1) ? 3 : (g_iMelodyTimeSignature == 2) ? 2 : 3, nPointPerBeat = POINTS_PER_BAR / nBeatsPerMeasure; if (g_iMelodyTimeSignature == 3) nPointPerBeat /= 2; if (g_bShowPlayTick) { int iBeat = dblStartPoint / nPointPerBeat, iTick = 120 * (dblStartPoint - iBeat * nPointPerBeat) / nPointPerBeat; sprintf(strTime, "%03d:%02d:%03d", iStartBar + 1, iBeat + 1, iTick); } else { UINT tStartTime = (INT)((iStartBar + dblStartPoint / POINTS_PER_BAR) * (double) nBeatsPerMeasure * 60000.0 / g_nMelodyTempo); sprintf(strTime, "%03d:%02d:%03d", tStartTime / 60000, (tStartTime % 60000) / 1000, tStartTime % 1000 ); } } void CALLBACK OnMediaTimer(UINT tTimerID, UINT msg, DWORD dwUser, DWORD dwl, DWORD dw2) { PostMessage((HWND)dwUser, MSG_MEDIATIME, 0, 0); } void UpdateGlobalStyle() { bool bChangGlobal = !g_lstComposeStages.empty(); for( int i=0; iidStyle==g_iSelectedStyleID ){ bChangGlobal = false; break; } } if( bChangGlobal ){ g_iSelectedStyleID = g_lstComposeStages[0]->idStyle; g_strSelectedStyleName = g_lstComposeStages[0]->strStyleName; } } void ClearFontList() { FONTINFOLIST::iterator iFI = g_lstFonts.begin(); while (iFI != g_lstFonts.end()) { delete(*iFI); iFI = g_lstFonts.erase(iFI); } } void ClearGlobalVars(int iOperation) { //g_bSongSaved = false; g_strMP3File = ""; if (iOperation & LIST_COMPLETEVOLS) { BARVOLSLIST::iterator iBV = g_lstCompleteVols.begin(); while (iBV != g_lstCompleteVols.end()) { delete(*iBV); iBV = g_lstCompleteVols.erase(iBV); } g_bSongLoaded = g_bSongNeedSave = false; } if (iOperation & LIST_COMPOSESTAGES) { COMPOSESTAGELIST::iterator iCS = g_lstComposeStages.begin(); while (iCS != g_lstComposeStages.end()) { delete(*iCS); iCS = g_lstComposeStages.erase(iCS); } g_bComposeLoaded = false; } if (iOperation & LIST_MELODYSTAGES) { MELODYSTAGELIST::iterator iMS = g_lstMelodyStages.begin(); while (iMS != g_lstMelodyStages.end()) { delete(*iMS); iMS = g_lstMelodyStages.erase(iMS); } g_bBaseComposeLoaded = false; } if (iOperation & LIST_MELODYBARS) { MELODYBARLIST::iterator iMB = g_lstMelodyBars.begin(); while (iMB != g_lstMelodyBars.end()) { delete(*iMB); iMB = g_lstMelodyBars.erase(iMB); } g_bAudioLoaded = false; } else if (iOperation & LIST_MELODYCHORDS) { MELODYBARLIST::iterator iMB = g_lstMelodyBars.begin(); while (iMB != g_lstMelodyBars.end()) { (*iMB)->iChords[0] = -1; (*iMB)->iChords[1] = -1; (*iMB)->iFill = -1; iMB++; } } if( (iOperation & LIST_MELODYVOLS) && g_bAudioLoaded ){ MELODYBARLIST::iterator iMB = g_lstMelodyBars.begin(); for( int i=0; itBarVol, 0, sizeof(BARVOLS) ); } g_bAudioLoaded = false; } if( iOperation==LIST_ALL ){ f_MM_ClearAudio(); } } void ClearSVDVars() { g_strFontFile_SVD.clear(); g_iSelectedStyleID_SVD = -1; g_iComposeKey_SVD = -1; g_iMelodyKey_SVD = -1; g_iMelodyTimeSignature_SVD = 0; g_nMelodyTempo_SVD = 75; g_nMelodyTempo_SVD = g_nMelodyTempo; g_fRecordVolume_SVD = g_fRecordVolume; g_fSpeakerVolume_SVD = g_fSpeakerVolume; g_fAudioVolume_SVD = g_fAudioVolume; g_fMusicVolume_SVD = g_fMusicVolume; MELODYBARLIST::iterator iMB = g_lstMelodyBars_SVD.begin(); while (iMB != g_lstMelodyBars_SVD.end()) { delete(*iMB); iMB = g_lstMelodyBars_SVD.erase(iMB); } MELODYSTAGELIST::iterator iMS = g_lstMelodyStages_SVD.begin(); while (iMS != g_lstMelodyStages_SVD.end()) { delete(*iMS); iMS = g_lstMelodyStages_SVD.erase(iMS); } COMPOSESTAGELIST::iterator iCS = g_lstComposeStages_SVD.begin(); while (iCS != g_lstComposeStages_SVD.end()) { delete(*iCS); iCS = g_lstComposeStages_SVD.erase(iCS); } BARVOLSLIST::iterator iBV = g_lstCompleteVols_SVD.begin(); while (iBV != g_lstCompleteVols_SVD.end()) { delete(*iBV); iBV = g_lstCompleteVols_SVD.erase(iBV); } } void SaveSVDVars() //add by tj 2013/12/31 { ClearSVDVars(); // 风格 g_iSelectedStyleID_SVD = g_iSelectedStyleID; // 旋律主要信息 g_iMelodyKey_SVD = g_iMelodyKey; g_iMelodyTimeSignature_SVD = g_iMelodyTimeSignature; g_nMelodyTempo_SVD = g_nMelodyTempo; // 音色库 g_strFontFile_SVD = g_strFontFile; // 各项音量设值 g_fRecordVolume_SVD = g_fRecordVolume; g_fSpeakerVolume_SVD = g_fSpeakerVolume; g_fAudioVolume_SVD = g_fAudioVolume; g_fMusicVolume_SVD = g_fMusicVolume; // 旋律小节表 int nMelodyBarNum = g_lstMelodyBars.size(); for (int i = 0; i < nMelodyBarNum; i++) { MELODYBAR * pSvdBar = new MELODYBAR; pSvdBar->iChords[0] = g_lstMelodyBars[i]->iChords[0]; pSvdBar->iChords[1] = g_lstMelodyBars[i]->iChords[1]; pSvdBar->iFill = g_lstMelodyBars[i]->iFill; pSvdBar->tBarVol.bRecording = g_lstMelodyBars[i]->tBarVol.bRecording; pSvdBar->tBarVol.bInvalid = g_lstMelodyBars[i]->tBarVol.bInvalid; for (int j = 0; j < POINTS_PER_BAR; j++) { pSvdBar->tBarVol.aVols[j] = g_lstMelodyBars[i]->tBarVol.aVols[j]; } g_lstMelodyBars_SVD.push_back(pSvdBar); } // 旋律分段信息 int nMelodyStageNum = g_lstMelodyStages.size(); for (int i = 0; i < nMelodyStageNum; i++) { MELODYSTAGE* pSvdMStage = new MELODYSTAGE; pSvdMStage->iFirstBar = g_lstMelodyStages[i]->iFirstBar; pSvdMStage->iLastBar = g_lstMelodyStages[i]->iLastBar; pSvdMStage->iVar = g_lstMelodyStages[i]->iVar; g_lstMelodyStages_SVD.push_back(pSvdMStage); } // 曲式分段信息 int nComposeStageNum = g_lstComposeStages.size(); for (int i = 0; i < nComposeStageNum; i++) { PCOMPOSESTAGE pCStage = g_lstComposeStages[i]; PCOMPOSESTAGE pSvdCStage = new COMPOSESTAGE; pSvdCStage->iMelodyStage = pCStage->iMelodyStage; pSvdCStage->nStageBars = pCStage->nStageBars; pSvdCStage->iVar = pCStage->iVar; pSvdCStage->idStyle = pCStage->idStyle; int nFillNum = pCStage->aFills.size(); for (int j = 0; j < nFillNum; j++) { pSvdCStage->aFills.push_back(pCStage->aFills[j]); } g_lstComposeStages_SVD.push_back(pSvdCStage); } // iComposeKey g_iComposeKey_SVD = g_iComposeKey; // 全曲 // 全曲小节音量 int nCompleteBarNum = g_lstCompleteVols.size(); for (int i = 0; i < nCompleteBarNum; i++) { BARVOLS* pSvdBV = new BARVOLS; pSvdBV->bRecording = g_lstCompleteVols[i]->bRecording; pSvdBV->bInvalid = g_lstCompleteVols[i]->bInvalid; for (int j = 0; j < POINTS_PER_BAR; j++) { pSvdBV->aVols[j] = g_lstCompleteVols[i]->aVols[j]; } g_lstCompleteVols_SVD.push_back(pSvdBV); } // 所处页面 // 音效 int nFxNum = MAX_FX_NUM; memcpy( g_aAudioEffects_SVD, g_aAudioEffects, sizeof(int)*nFxNum ); } wstring GetElementInfo(int iElem, int iList) { wstring strInfo; if (iList == LIST_MELODYSTAGES) { PMELODYSTAGE pMStage = g_lstMelodyStages[iElem]; strInfo = L"旋律"; strInfo += GetStageName(iElem); strInfo += L"段 "; strInfo += str2wstr(g_strStageVar[pMStage->iVar % STAGE_VAR_NUM]); } else if (iList == LIST_COMPOSESTAGES) { PCOMPOSESTAGE pCStage = g_lstComposeStages[iElem]; if (pCStage->iMelodyStage >= COMPOSE_ENDING_1) { TCHAR buffer[65]; strInfo = L"尾奏 (类型 "; strInfo += _itow(pCStage->iMelodyStage - COMPOSE_ENDING_1 + 1, buffer, 10); } else if (pCStage->iMelodyStage >= COMPOSE_INTRO_1) { TCHAR buffer[65]; if (iElem == 0) { strInfo = L"前奏 (类型 "; } else { strInfo = L"间奏 (类型 "; } strInfo += _itow(pCStage->iMelodyStage - COMPOSE_INTRO_1 + 1, buffer, 10); strInfo += L")"; } else { strInfo = L"旋律"; strInfo += GetStageName(pCStage->iMelodyStage); strInfo += L"段 "; strInfo += str2wstr(g_strStageVar[pCStage->iVar % STAGE_VAR_NUM]); } if( !strInfo.empty() ){ strInfo += L"\n风格:"; if( pCStage->idStyle==g_iSelectedStyleID ){ strInfo += str2wstr(g_strSelectedStyleName); } else{ strInfo += str2wstr(pCStage->strStyleName); } } } return strInfo; } wstring GetStageName(int iStage) { wstring strName; strName += TCHAR('A' + (iStage % 26)); int nNum = iStage / 26; while (nNum > 0) { wstring strTemp; strTemp += TCHAR('A' + (nNum % 26)); strTemp += strName; strName = strTemp; nNum /= 26; } return strName; } #include #include #include #include #define MAX_DEBUG_PRINT 10240 string wstr2str(const wstring& _src) { int nBufSize = WideCharToMultiByte(GetACP(), 0, _src.c_str(), -1, NULL, 0, 0, FALSE); char *szBuf = new char[nBufSize]; WideCharToMultiByte(GetACP(), 0, _src.c_str(), -1, szBuf, nBufSize, 0, FALSE); string strRet(szBuf); delete[]szBuf; return strRet; } wstring str2wstr(const string& _src) { int nBufSize = MultiByteToWideChar(GetACP(), 0, _src.c_str(), -1, NULL, 0); wchar_t *wsBuf = new wchar_t[nBufSize]; MultiByteToWideChar(GetACP(), 0, _src.c_str(), -1, wsBuf, nBufSize); wstring wstrRet(wsBuf); delete[]wsBuf; return wstrRet; } string UTF8ToMBCS(const char *pcUtf8) { // wchar_t pcUnicode[CHAR_BUFSIZE]; int nUnicodeLen = MultiByteToWideChar(CP_UTF8, 0, pcUtf8, -1, NULL, 0); wchar_t * pcUnicode = new wchar_t[nUnicodeLen + 1]; memset(pcUnicode, 0, nUnicodeLen * 2 + 2); // utf8 to unicode MultiByteToWideChar(CP_UTF8, 0, pcUtf8, -1, pcUnicode, nUnicodeLen); // unicode to gb2312 int nMBCSLen = WideCharToMultiByte(CP_ACP, 0, pcUnicode, -1, NULL, 0, NULL, NULL); char *pcMBCS = new char[nMBCSLen + 1]; memset(pcMBCS, 0, nMBCSLen + 1); WideCharToMultiByte(CP_ACP, 0, pcUnicode, -1, pcMBCS, nMBCSLen, NULL, NULL); string strMBCS = pcMBCS; delete[]pcMBCS; delete[]pcUnicode; return strMBCS; } string GBToUTF8(const char* str) { string result; WCHAR *strSrc; char *szRes; //获得临时变量的大小 int i = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); strSrc = new WCHAR[i+1]; MultiByteToWideChar(CP_ACP, 0, str, -1, strSrc, i); //获得临时变量的大小 i = WideCharToMultiByte(CP_UTF8, 0, strSrc, -1, NULL, 0, NULL, NULL); szRes = new char[i+1]; int j = WideCharToMultiByte(CP_UTF8, 0, strSrc,-1, szRes, i, NULL, NULL); result = szRes; delete []strSrc; delete []szRes; return result; } void DebugPrint(const char * fmt, ...) { #ifdef _DEBUG char sDebug[MAX_DEBUG_PRINT]; sDebug[0] = '\0'; char tbuffer[9]; _strtime(tbuffer); sprintf(sDebug, "[%s] ", tbuffer); va_list vaParams; va_start(vaParams, fmt); vsprintf(sDebug + strlen(sDebug), fmt, vaParams); OutputDebugStringA(sDebug); #endif } BOOL SaveProject( LPCSTR strProjectName, int iMode, HWND hNotifyWnd ) { wstring wstrProj = str2wstr( strProjectName ); DebugPrint("Saving project...."); WaitForSingleObject(g_hProjectEvent, INFINITE); BOOL bSuccess = FALSE; FILE *pFile = NULL; if ((pFile = fopen( strProjectName, "w+b" )) != NULL) { long lFileSize = 0; fpos_t posFileSize = 0; // 保存版本号 fwrite(&g_dwProjectVersion, sizeof(DWORD), 1, pFile); // 预留文件长度 fgetpos(pFile, &posFileSize); fwrite(&lFileSize, sizeof(long), 1, pFile); // 保存模式标志 fwrite(&iMode, sizeof(int), 1, pFile); // 风格类型 7.23 fwrite(&g_iSelectedStyleType, sizeof(DWORD), 1, pFile); // 风格 fwrite(&g_iSelectedStyleID, sizeof(int), 1, pFile); // 旋律主要信息 fwrite(&g_bMidiMelody, sizeof(bool), 1, pFile); //是否为MIDI旋律 fwrite(&g_iMelodyTimeSignature, sizeof(int), 1, pFile); // 拍号 fwrite(&g_nMelodyTempo, sizeof(int), 1, pFile); // 速度 fwrite(&g_iMelodyKey, sizeof(int), 1, pFile); // 调号 // 音色库 string strFont = wstr2str( g_strFontFile ); string strFontUTF8 = GBToUTF8( strFont.c_str() ); int nFontNameLen = strFontUTF8.length() + 1; fwrite(&nFontNameLen, sizeof(int), 1, pFile); fwrite( strFontUTF8.c_str(), sizeof(char), nFontNameLen, pFile); // 各项音量设值 fwrite(&g_fRecordVolume, sizeof(float), 1, pFile); fwrite(&g_fSpeakerVolume, sizeof(float), 1, pFile); fwrite(&g_fAudioVolume, sizeof(float), 1, pFile); fwrite(&g_fMusicVolume, sizeof(float), 1, pFile); int nMelodyBarNum = g_lstMelodyBars.size(); // 旋律小节表 fwrite(&nMelodyBarNum, sizeof(int), 1, pFile); // DWORD dwVols[POINTS_PER_BAR]; // memset( dwVols, 0, sizeof(DWORD)*POINTS_PER_BAR ); for (int i = 0; i < nMelodyBarNum; i++) { fwrite(&g_lstMelodyBars[i]->iChords[0], sizeof(char), 1, pFile); fwrite(&g_lstMelodyBars[i]->iChords[1], sizeof(char), 1, pFile); fwrite(&g_lstMelodyBars[i]->iFill, sizeof(char), 1, pFile); if( iMode!=PROJ_MODE_UPLOAD ){ fwrite(g_lstMelodyBars[i]->tBarVol.aVols, sizeof(DWORD), POINTS_PER_BAR, pFile); } } // 旋律分段信息 int nMelodyStageNum = g_lstMelodyStages.size(); fwrite(&nMelodyStageNum, sizeof(int), 1, pFile); for (int i = 0; i < nMelodyStageNum; i++) { fwrite(&g_lstMelodyStages[i]->iFirstBar, sizeof(int), 1, pFile); fwrite(&g_lstMelodyStages[i]->iLastBar, sizeof(int), 1, pFile); fwrite(&g_lstMelodyStages[i]->iVar, sizeof(int), 1, pFile); } // 曲式分段信息 int nComposeStageNum = g_lstComposeStages.size(); fwrite(&nComposeStageNum, sizeof(int), 1, pFile); for (int i = 0; i < nComposeStageNum; i++) { PCOMPOSESTAGE pCStage = g_lstComposeStages[i]; fwrite(&pCStage->iMelodyStage, sizeof(int), 1, pFile); fwrite(&pCStage->nStageBars, sizeof(int), 1, pFile); fwrite(&pCStage->iVar, sizeof(int), 1, pFile); fwrite(&pCStage->idStyle, sizeof(int), 1, pFile); int nFillNum = pCStage->aFills.size(); fwrite(&nFillNum, sizeof(int), 1, pFile); for (int j = 0; j < nFillNum; j++) { fwrite(&pCStage->aFills[j], sizeof(DWORD), 1, pFile); } } // iComposeKey fwrite(&g_iComposeKey, sizeof(int), 1, pFile); // 全曲 // 全曲小节音量 int nCompleteBarNum = iMode==PROJ_MODE_UPLOAD ? 0 : g_lstCompleteVols.size(); fwrite(&nCompleteBarNum, sizeof(int), 1, pFile); for (int i = 0; i < nCompleteBarNum; i++) { fwrite( g_lstCompleteVols[i]->aVols, sizeof(DWORD), POINTS_PER_BAR, pFile); } // 所处页面 fwrite(&g_iCurrentPage, sizeof(int), 1, pFile); int nFxNum = MAX_FX_NUM; fwrite( &nFxNum, sizeof(int), 1, pFile ); fwrite( g_aAudioEffects, sizeof(int), nFxNum, pFile ); //预设工程 fwrite( &g_bPredefine, sizeof(bool), 1, pFile ); // 保存文件长度 lFileSize = ftell(pFile); fclose( pFile ); int lCSSize = f_CS_SaveProject( strProjectName ); if( lCSSize>0 ){ lFileSize += lCSSize; } long lMMSize = f_MM_SaveProject( iMode, hNotifyWnd, strProjectName ); if( lMMSize>0 ){ lFileSize += lMMSize; } pFile = fopen( strProjectName, "r+b" ); fsetpos(pFile, &posFileSize); fwrite(&lFileSize, sizeof(long), 1, pFile); fclose(pFile); bSuccess = TRUE; if( iMode==PROJ_MODE_NORMAL ){ //add by tj 2013/12/30 g_bProjStylePaid = false; ClearAutoProj(); SaveSVDVars(); PostMessage(hNotifyWnd, MSG_OPERATE_COMPLETE, 0, 0); UpdateRecentProject(wstrProj); } else if( iMode==PROJ_MODE_AUTO ){ g_bAutoSave = true; SetAutoSaveReg(); } } if (SetEvent(g_hProjectEvent) == 0) { DWORD dwError = GetLastError(); DebugPrint("Set Event error! err=%d", dwError); } DebugPrint("saving done\n"); if( iMode==PROJ_MODE_NORMAL ){ //add by tj 2013/12/26 if (bSuccess) { g_strProjectName = wstrProj; } else { PostMessage(hNotifyWnd, MSG_OPERATE_FAILED, E_PROJ_FILENOTEXIST, 0); } } return bSuccess; } #include BOOL LoadProject(LPCTSTR strProjectName, HWND hNotifyWnd) { DebugPrint("Opening project...."); WaitForSingleObject(g_hProjectEvent, INFINITE); // bool bAutoSave = hNotifyWnd==NULL; int iMode = hNotifyWnd==NULL ? PROJ_MODE_AUTO : PROJ_MODE_NORMAL; BOOL bSuccess = FALSE; int iError = E_PROJ_NOERROR; g_iCurrentPage = -1; FILE *pFile = NULL; if ((pFile = _wfsopen(strProjectName, L"rb", SH_DENYWR)) != NULL) { DWORD dwProjectVersion; WORD wMajVersion, wMinVersion; long lFileSize = 0; fpos_t posBegin = 0; // 读取版本号 fread(&dwProjectVersion, sizeof(DWORD), 1, pFile); if( LOWORD(dwProjectVersion)<2 ){ wMajVersion = LOWORD(dwProjectVersion); wMinVersion = HIWORD(dwProjectVersion); dwProjectVersion = MAKELONG( wMinVersion, wMajVersion ); //修改版本号 // fsetpos(pFile, &posBegin); // fwrite( &dwProjectVersion, sizeof(DWORD), 1, pFile ); } else{ wMajVersion = HIWORD( dwProjectVersion ); wMinVersion = LOWORD( dwProjectVersion ); } // 读取文件长度 fread(&lFileSize, sizeof(long), 1, pFile); // 检测文件长度 fgetpos(pFile, &posBegin); fseek(pFile, 0, SEEK_END); if (lFileSize != ftell(pFile)) { iError = E_PROJ_FILECRUPT; goto STATEMENT_FALSE; } else { fsetpos(pFile, &posBegin); } g_bPredefine = false; if( wMajVersion<1 || wMajVersion>5 ){ iError = E_PROJ_INVALIDVERSION; goto STATEMENT_FALSE; } else if( wMajVersion>2 ){ iError = E_PROJ_PROVERSION; goto STATEMENT_FALSE; } else if( dwProjectVersion>g_dwProjectVersion ) { iError = E_PROJ_LATERVERSION; goto STATEMENT_FALSE; } if( wMajVersion==2 && wMinVersion>=7 ){ fread(&iMode, sizeof(int), 1, pFile); } if( wMajVersion==1 ){ iError = LoadVersion1(pFile, strProjectName, dwProjectVersion, hNotifyWnd); if (iError!=E_PROJ_NOERROR && iError!=E_PROJ_INVALSTAGESTYLE) { goto STATEMENT_FALSE; } if( wMinVersion<1 ){ int nBarNum = g_lstMelodyBars.size(), nBeatsPerMeasure = g_iMelodyTimeSignature == 0 ? 4 : g_iMelodyTimeSignature == 1 ? 3 : g_iMelodyTimeSignature == 2 ? 2 : 3; DWORD msValid = nBarNum * nBeatsPerMeasure * 60000 / g_nMelodyTempo; f_MM_SetStreamLength(2, msValid + 100); } } else if( wMajVersion==2 ){ iError = LoadVersion2( pFile, dwProjectVersion, hNotifyWnd, iMode ); long lPos = ftell( pFile ); fclose( pFile ); if (iError!=E_PROJ_NOERROR && iError!=E_PROJ_INVALSTAGESTYLE) { goto STATEMENT_FALSE; } string strProj = wstr2str( strProjectName ); if( wMinVersion>=6 ){ int nCSSize = f_CS_LoadProject( strProj.c_str(), lPos, dwProjectVersion ); if( nCSSize<0 ){ iError = E_PROJ_FILECRUPT; goto STATEMENT_FALSE; } lPos += nCSSize; } if( f_MM_LoadProject( iMode, hNotifyWnd, strProj.c_str(), lPos, dwProjectVersion)!=0 ){ iError = E_PROJ_FILECRUPT; goto STATEMENT_FALSE; } if( f_MM_GetStreamLength(2)>0 ){ SetWavNotes(); g_bAudioLoaded = true; } else{ // g_iMelodyKey_SVD = g_iMelodyKey = -1; ClearGlobalVars( LIST_MELODYVOLS ); g_bPredefine = true; f_SM_InputWavNotes(NULL, NULL, 0, 192, (BYTE)g_iMelodyTimeSignature, g_nMelodyTempo, NULL); } if( f_MM_GetStreamLength(5)>0 ) { g_bSongLoaded = true; } if( f_MM_GetStreamLength(6)>0 ) { g_bSongNeedSave = true; } else { ClearGlobalVars(LIST_COMPLETEVOLS); } } g_bkMelody.Clear(); g_bkCompose.Clear(); bSuccess = TRUE; if( hNotifyWnd ) { //add by tj 2013/12/31 PostMessage(hNotifyWnd, MSG_OPERATE_COMPLETE, iError, 0); SaveSVDVars(); } STATEMENT_FALSE: if( wMajVersion<2 ) fclose(pFile); } else { iError = E_PROJ_FILENOTEXIST; } if (SetEvent(g_hProjectEvent) == 0) { DWORD dwError = GetLastError(); DebugPrint("Set Event error! err=%d", dwError); } DebugPrint("opening done\n"); if( hNotifyWnd ) { //add by tj 2013/12/31 if (!bSuccess) { PostMessage(hNotifyWnd, MSG_OPERATE_FAILED, iError, 0); } else { UpdateRecentProject(strProjectName); g_strProjectName = strProjectName; } } return bSuccess; } int LoadVersion2( FILE *pFile, DWORD dwVersion, HWND hNotifyWnd, int iMode ) { int nSize, iMelodyKey, iMelodyTimeSignature, nMelodyTempo, nMelodyBarNum, nMelodyStageNum, nComposeStageNum, nCompleteBarNum; char strFontFile[MAX_PATH]; string strStyleName; bool bUseful; int iError = E_PROJ_NOERROR; WORD wMinVersion = LOWORD( dwVersion ); // 读取风格 int iStyleID; fread(&g_iSelectedStyleType, sizeof(DWORD), 1, pFile); fread(&iStyleID, sizeof(int), 1, pFile); TSTYLEINFO infoStyle; HRESULT ret = f_SM_GetStyleInfo(iStyleID, &infoStyle); if( ret==0 ){ bUseful = f_SM_CheckStyle(iStyleID); if (!bUseful) { if( f_CS_DownloadStyle( iStyleID, NULL )!=0 ){ return E_PROJ_INVALIDSTYLE; } } } else { DebugPrint("MF_GetStyleInfo error. err=%d", ret); return E_PROJ_INVALIDSTYLE; } // 读取主旋律信息 if( wMinVersion!=3 ) fread(&g_bMidiMelody, sizeof(bool), 1, pFile); fread(&iMelodyTimeSignature, sizeof(int), 1, pFile); fread(&nMelodyTempo, sizeof(int), 1, pFile); fread(&iMelodyKey, sizeof(int), 1, pFile); SetMelodyTS(iMelodyTimeSignature); SetMelodyTempo(nMelodyTempo); g_iMelodyKey = iMelodyKey; g_iSelectedStyleID = iStyleID; // 提取风格名称 g_strSelectedStyleName = UTF8ToMBCS( infoStyle.detail.strStyleName ).c_str(); //iStyleID g_lstStyleSelected.clear(); g_iSelectedStyleType = 0; for( int i=0; i9 ) iType = 9; g_iSelectedStyleType |= (1 << iType); } for( int j=0; j<32; j++ ){ if( g_iSelectedStyleType & (1< 0) { fread(strFontFile, sizeof(char), nSize, pFile); string strFontGB = UTF8ToMBCS( strFontFile ); wstring wstrFont = str2wstr( strFontGB ); g_strFontFile = wstrFont; } // 各项音量设值 fread(&g_fRecordVolume, sizeof(float), 1, pFile); fread(&g_fSpeakerVolume, sizeof(float), 1, pFile); fread(&g_fAudioVolume, sizeof(float), 1, pFile); fread(&g_fMusicVolume, sizeof(float), 1, pFile); f_MM_SetStreamVolume( 0, g_fSpeakerVolume ); f_MM_SetStreamVolume( 1, g_fRecordVolume ); f_MM_SetStreamVolume( 2, g_fAudioVolume ); f_MM_SetStreamVolume( 3, g_fMusicVolume ); // 全局变量赋值 ClearGlobalVars(); // 旋律小节表 fread(&nMelodyBarNum, sizeof(int), 1, pFile); for (int i = 0; i < nMelodyBarNum; i++) { MELODYBAR * pMBar = new MELODYBAR; fread(&pMBar->iChords[0], sizeof(char), 1, pFile); fread(&pMBar->iChords[1], sizeof(char), 1, pFile); fread(&pMBar->iFill, sizeof(char), 1, pFile); pMBar->tBarVol.bRecording = false; pMBar->tBarVol.bInvalid = false; if( iMode==PROJ_MODE_UPLOAD && wMinVersion>=8 ) memset( pMBar->tBarVol.aVols, 0, sizeof(DWORD) * POINTS_PER_BAR ); else fread(pMBar->tBarVol.aVols, sizeof(DWORD), POINTS_PER_BAR, pFile); g_lstMelodyBars.push_back(pMBar); } // 旋律分段信息 fread(&nMelodyStageNum, sizeof(int), 1, pFile); for (int i = 0; i < nMelodyStageNum; i++) { MELODYSTAGE * pMStage = new MELODYSTAGE; fread(&pMStage->iFirstBar, sizeof(int), 1, pFile); fread(&pMStage->iLastBar, sizeof(int), 1, pFile); fread(&pMStage->iVar, sizeof(int), 1, pFile); g_lstMelodyStages.push_back(pMStage); } /*///////////////////////////// //临时代码 int iDel = -1; for( int i=0; iiLastBar<0 || pMStage->iLastBar>=nMelodyBarNum ){ pMStage->iLastBar = nMelodyBarNum - 1; } if( pMStage->iFirstBar<0 || pMStage->iFirstBar>=nMelodyBarNum ){ iDel = i; break; } } if( iDel>=0 ){ for( int i=g_lstMelodyStages.size()-1; i>=iDel; i-- ){ delete g_lstMelodyStages[i]; g_lstMelodyStages.erase( g_lstMelodyStages.begin()+i ); } } // *///////////////////////////// // 曲式分段信息 fread(&nComposeStageNum, sizeof(int), 1, pFile); for (int i = 0; i < nComposeStageNum; i++) { COMPOSESTAGE * pCStage = new COMPOSESTAGE; fread(&pCStage->iMelodyStage, sizeof(int), 1, pFile); fread(&pCStage->nStageBars, sizeof(int), 1, pFile); fread(&pCStage->iVar, sizeof(int), 1, pFile); fread(&pCStage->idStyle, sizeof(int), 1, pFile); if( pCStage->idStyle!=g_iSelectedStyleID ){ // 提取风格名称 if( f_SM_GetStyleInfo(pCStage->idStyle, &infoStyle)==0 && ( infoStyle.state==e_Downloaded || f_CS_DownloadStyle( pCStage->idStyle, NULL )==0 ) ){ pCStage->strStyleName = UTF8ToMBCS( infoStyle.detail.strStyleName ).c_str(); } else { pCStage->idStyle = g_iSelectedStyleID; if( pCStage->iMelodyStage>=COMPOSE_ENDING_1 ){ int iEnding = pCStage->iMelodyStage - COMPOSE_ENDING_1; if( infoStyle.detail.aEndingBars[iEnding]>0 ){ pCStage->nStageBars = infoStyle.detail.aEndingBars[iEnding]; } else{ pCStage->iMelodyStage = COMPOSE_ENDING_1; pCStage->nStageBars = infoStyle.detail.aEndingBars[0]; } } else if( pCStage->iMelodyStage>=COMPOSE_INTRO_1 ){ int iIntro = pCStage->iMelodyStage - COMPOSE_INTRO_1; if( infoStyle.detail.aIntroBars[iIntro]>0 ){ pCStage->nStageBars = infoStyle.detail.aIntroBars[iIntro]; } else{ pCStage->iMelodyStage = COMPOSE_INTRO_1; pCStage->nStageBars = infoStyle.detail.aIntroBars[0]; } } iError = E_PROJ_INVALSTAGESTYLE; } } int nFillNum; fread(&nFillNum, sizeof(int), 1, pFile); for (int j = 0; j < nFillNum; j++) { DWORD dwFill; fread(&dwFill, sizeof(DWORD), 1, pFile); pCStage->aFills.push_back(dwFill); } g_lstComposeStages.push_back(pCStage); } // 全曲录音信息 fread(&g_iComposeKey, sizeof(int), 1, pFile); // 全曲小节音量 fread(&nCompleteBarNum, sizeof(int), 1, pFile); for (int i = 0; i < nCompleteBarNum; i++) { BARVOLS * pBVols = new BARVOLS; pBVols->bRecording = false; fread(pBVols->aVols, sizeof(DWORD), POINTS_PER_BAR, pFile); g_lstCompleteVols.push_back(pBVols); } // 所处页面 fread(&g_iCurrentPage, sizeof(int), 1, pFile); //音效 memset( g_aAudioEffects, 0, MAX_FX_NUM*sizeof(int) ); int nFxNum; fread( &nFxNum, sizeof(int), 1, pFile ); if( nFxNum>0 ){ fread( g_aAudioEffects, sizeof(int), nFxNum, pFile ); for( int i=0; i=5 ) fread( &g_bPredefine, sizeof(bool), 1, pFile ); return iError; } int LoadVersion1(FILE *pFile, LPCTSTR strProjectName, DWORD dwVersion, HWND hNotifyWnd) { bool bAutoSave = false; //add by tj 2013/12/31 if(hNotifyWnd==NULL) bAutoSave = true; int nSize, iMelodyKey, iMelodyTimeSignature, nMelodyTempo, nMelodyBarNum, nMelodyStageNum, nComposeStageNum, nCompleteBarNum; long posBegin; DWORD lAudioSize = 0, lSongSize = 0; fpos_t posAudioBegin = 0, posSongBegin = 0; TCHAR strFontFile[MAX_PATH]; string strStyleName; bool bUseful; WORD wMinVersion = LOWORD( dwVersion ); int iError = E_PROJ_NOERROR; // 全局变量赋值 ClearGlobalVars(); fread(&lAudioSize, sizeof(long), 1, pFile); fread(&lSongSize, sizeof(long), 1, pFile); int nextRange = 90; if (lAudioSize > 0) { nextRange = 90 * lAudioSize / (lAudioSize + lSongSize); } posBegin = ftell(pFile); if (lAudioSize > 0) { if(!bAutoSave) //add by tj 2013/12/31 PostMessage(hNotifyWnd, MSG_OPERATE_NEXTRANGE, 0, nextRange); // 旋律音频 posAudioBegin = posBegin; nSize = f_MM_LoadAudioMP3(hNotifyWnd, strProjectName, posAudioBegin, dwVersion ); if (nSize > 0) { // 旋律识别信息 posBegin += nSize +sizeof(DWORD); nSize = f_MM_LoadAnalysis(hNotifyWnd, strProjectName, posBegin, dwVersion); if (nSize > 0) { posBegin += nSize +sizeof(DWORD); } if(!bAutoSave){ //add by tj 2013/12/31 PostMessage(hNotifyWnd, MSG_OPERATE_NEXTRANGE, 0, 0); PostMessage(hNotifyWnd, MSG_OPERATE_PERCENT, 5 + nextRange, 0); } } else { return E_PROJ_CANTLOADAUDIO; } } // 读取风格 int iStyleID; fsetpos(pFile, &posBegin); if( wMinVersion>1 ) fread(&g_iSelectedStyleType, sizeof(DWORD), 1, pFile); fread(&iStyleID, sizeof(int), 1, pFile); TSTYLEINFO infoStyle; HRESULT ret = f_SM_GetStyleInfo(iStyleID, &infoStyle); if( ret==0 ){ bUseful = f_SM_CheckStyle(iStyleID); if (!bUseful) { if( f_CS_DownloadStyle( iStyleID, NULL )!=0 ){ return E_PROJ_INVALIDSTYLE; } } } else { DebugPrint("MF_GetStyleInfo error. err=%d", ret); return E_PROJ_INVALIDSTYLE; } // 读取主旋律信息 if( wMinVersion>=4 ){ fread(&g_bMidiMelody, sizeof(bool), 1, pFile); } else{ g_bMidiMelody = false; } fread(&iMelodyTimeSignature, sizeof(int), 1, pFile); fread(&nMelodyTempo, sizeof(int), 1, pFile); fread(&iMelodyKey, sizeof(int), 1, pFile); SetMelodyTS(iMelodyTimeSignature); f_MM_SetTimeSignature(iMelodyTimeSignature); SetMelodyTempo(nMelodyTempo); g_iMelodyKey = iMelodyKey; g_iSelectedStyleID = iStyleID; // 提取风格名称 g_strSelectedStyleName = UTF8ToMBCS( infoStyle.detail.strStyleName ).c_str(); g_lstStyleSelected.clear(); g_iSelectedStyleType = 0; for( int i=0; i9 ) iType = 9; g_iSelectedStyleType |= (1 << iType); } for( int j=0; j<32; j++ ){ if( g_iSelectedStyleType & (1< 0) { SetWavNotes(); } else{ g_iMelodyKey_SVD = g_iMelodyKey = -1; } // 读取音色库文件名 fread(&nSize, sizeof(int), 1, pFile); if (nSize > 0) { fread(strFontFile, sizeof(TCHAR), nSize, pFile); } g_strFontFile = strFontFile; // 各项音量设值 fread(&g_fRecordVolume, sizeof(float), 1, pFile); fread(&g_fSpeakerVolume, sizeof(float), 1, pFile); fread(&g_fAudioVolume, sizeof(float), 1, pFile); fread(&g_fMusicVolume, sizeof(float), 1, pFile); f_MM_SetStreamVolume( 0, g_fSpeakerVolume ); f_MM_SetStreamVolume( 1, g_fRecordVolume ); f_MM_SetStreamVolume( 2, g_fAudioVolume ); f_MM_SetStreamVolume( 3, g_fMusicVolume ); // 旋律小节表 fread(&nMelodyBarNum, sizeof(int), 1, pFile); for (int i = 0; i < nMelodyBarNum; i++) { MELODYBAR * pMBar = new MELODYBAR; fread(&pMBar->iChords[0], sizeof(char), 1, pFile); fread(&pMBar->iChords[1], sizeof(char), 1, pFile); fread(&pMBar->iFill, sizeof(char), 1, pFile); pMBar->tBarVol.bRecording = false; pMBar->tBarVol.bInvalid = false; fread(pMBar->tBarVol.aVols, sizeof(DWORD), POINTS_PER_BAR, pFile); g_lstMelodyBars.push_back(pMBar); } if (lAudioSize > 0) { g_bAudioLoaded = true; } // 旋律分段信息 fread(&nMelodyStageNum, sizeof(int), 1, pFile); for (int i = 0; i < nMelodyStageNum; i++) { MELODYSTAGE * pMStage = new MELODYSTAGE; fread(&pMStage->iFirstBar, sizeof(int), 1, pFile); fread(&pMStage->iLastBar, sizeof(int), 1, pFile); fread(&pMStage->iVar, sizeof(int), 1, pFile); g_lstMelodyStages.push_back(pMStage); } // 曲式分段信息 fread(&nComposeStageNum, sizeof(int), 1, pFile); for (int i = 0; i < nComposeStageNum; i++) { COMPOSESTAGE * pCStage = new COMPOSESTAGE; fread(&pCStage->iMelodyStage, sizeof(int), 1, pFile); fread(&pCStage->nStageBars, sizeof(int), 1, pFile); fread(&pCStage->iVar, sizeof(int), 1, pFile); fread(&pCStage->idStyle, sizeof(int), 1, pFile); if( pCStage->idStyle!=g_iSelectedStyleID ){ // 提取风格名称 if( f_SM_GetStyleInfo(pCStage->idStyle, &infoStyle)==0 && ( infoStyle.state==e_Downloaded || f_CS_DownloadStyle( pCStage->idStyle, NULL )==0 ) ){ pCStage->strStyleName = UTF8ToMBCS( infoStyle.detail.strStyleName ).c_str(); } else{ pCStage->idStyle = g_iSelectedStyleID; if( pCStage->iMelodyStage>=COMPOSE_ENDING_1 ){ int iEnding = pCStage->iMelodyStage - COMPOSE_ENDING_1; if( infoStyle.detail.aEndingBars[iEnding]>0 ){ pCStage->nStageBars = infoStyle.detail.aEndingBars[iEnding]; } else{ pCStage->iMelodyStage = COMPOSE_ENDING_1; pCStage->nStageBars = infoStyle.detail.aEndingBars[0]; } } else if( pCStage->iMelodyStage>=COMPOSE_INTRO_1 ){ int iIntro = pCStage->iMelodyStage - COMPOSE_INTRO_1; if( infoStyle.detail.aIntroBars[iIntro]>0 ){ pCStage->nStageBars = infoStyle.detail.aIntroBars[iIntro]; } else{ pCStage->iMelodyStage = COMPOSE_INTRO_1; pCStage->nStageBars = infoStyle.detail.aIntroBars[0]; } } iError = E_PROJ_INVALSTAGESTYLE; } } int nFillNum; fread(&nFillNum, sizeof(int), 1, pFile); for (int j = 0; j < nFillNum; j++) { DWORD dwFill; fread(&dwFill, sizeof(DWORD), 1, pFile); pCStage->aFills.push_back(dwFill); } g_lstComposeStages.push_back(pCStage); } // 全曲录音信息 fread(&g_iComposeKey, sizeof(int), 1, pFile); if(!bAutoSave) //add by tj 2013/12/31 PostMessage(hNotifyWnd, MSG_OPERATE_PERCENT, 10 + nextRange, 0); if (lSongSize > 0) { // 全曲小节音量 fread(&nCompleteBarNum, sizeof(int), 1, pFile); for (int i = 0; i < nCompleteBarNum; i++) { BARVOLS * pBVols = new BARVOLS; pBVols->bRecording = false; fread(pBVols->aVols, sizeof(DWORD), POINTS_PER_BAR, pFile); g_lstCompleteVols.push_back(pBVols); } posBegin = ftell(pFile); posSongBegin = posBegin; if(!bAutoSave) //add by tj 2013/12/31 PostMessage(hNotifyWnd, MSG_OPERATE_NEXTRANGE, 10 + nextRange, 0); nSize = f_MM_LoadSongMP3(hNotifyWnd, strProjectName, posSongBegin, dwVersion ); if (nSize > sizeof(long)+sizeof(int)) { g_bSongLoaded = true; g_bSongNeedSave = true; posBegin += nSize +sizeof(long); fsetpos(pFile, &posBegin); } else { ClearGlobalVars(LIST_COMPLETEVOLS); } } // 所处页面 fread(&g_iCurrentPage, sizeof(int), 1, pFile); //音效 bool bResetAudioEffect = true; if( wMinVersion>=5 ){ memset( g_aAudioEffects, 0, MAX_FX_NUM*sizeof(int) ); int nFxNum; fread( &nFxNum, sizeof(int), 1, pFile ); if( nFxNum>0 ){ fread( g_aAudioEffects, sizeof(int), nFxNum, pFile ); for( int i=0; i 0) { vector::iterator iterStr = g_lstRecentProject.begin() + i; g_lstRecentProject.erase(iterStr); g_lstRecentProject.insert(g_lstRecentProject.begin(), wstrProj); } bInList = TRUE; break; } } if (!bInList) { g_lstRecentProject.insert(g_lstRecentProject.begin(), wstrProj); } } BOOL HasProjectModified(int idStyle) { if( g_lstMelodyBars.empty() ) return false; if( g_bProjStylePaid ) return TRUE; if (idStyle == -1) { idStyle = g_iSelectedStyleID; } // 基本信息 if (g_iMelodyKey_SVD != g_iMelodyKey || g_iComposeKey_SVD != g_iComposeKey && (g_iComposeKey_SVD != -1 || g_iComposeKey != g_iMelodyKey) || g_iSelectedStyleID_SVD != idStyle || g_fAudioVolume_SVD != g_fAudioVolume || g_fMusicVolume_SVD != g_fMusicVolume ){ return TRUE; } if( g_strProjectName.length()>0 && ( g_fRecordVolume_SVD != g_fRecordVolume || g_fSpeakerVolume_SVD != g_fSpeakerVolume || g_strFontFile_SVD.compare(g_strFontFile) )){ return TRUE; } // 旋律小节 if (g_lstMelodyBars_SVD.size() != g_lstMelodyBars.size()) { return TRUE; } else { for (int i = 0; i < g_lstMelodyBars.size(); i++) { PMELODYBAR pSvdBar = g_lstMelodyBars_SVD[i], pMBar = g_lstMelodyBars[i]; if (pSvdBar->iChords[0] != pMBar->iChords[0] || pSvdBar->iChords[1] != pMBar->iChords[1] || pSvdBar->iFill != pMBar->iFill || pSvdBar->tBarVol.bRecording != pMBar->tBarVol.bRecording || pSvdBar->tBarVol.bInvalid != pMBar->tBarVol.bInvalid) { return TRUE; } else { for (int j = 0; j < POINTS_PER_BAR; j++) { if (pSvdBar->tBarVol.aVols[j] != pMBar->tBarVol.aVols[j]) { return TRUE; } } } } } // 旋律分段 if (g_lstMelodyStages_SVD.size() != g_lstMelodyStages.size()) { return TRUE; } else { for (int i = 0; i < g_lstMelodyStages.size(); i++) { PMELODYSTAGE pSvdStage = g_lstMelodyStages_SVD[i], pMStage = g_lstMelodyStages[i]; if (pSvdStage->iFirstBar != pMStage->iFirstBar || pSvdStage->iLastBar != pMStage->iLastBar || pSvdStage->iVar != pMStage->iVar) { return TRUE; } } } // 曲式分段 if (g_lstComposeStages_SVD.size() != g_lstComposeStages.size()) { return TRUE; } else { for (int i = 0; i < g_lstComposeStages.size(); i++) { PCOMPOSESTAGE pSvdStage = g_lstComposeStages_SVD[i], pCStage = g_lstComposeStages[i]; if (pSvdStage->iMelodyStage != pCStage->iMelodyStage || pSvdStage->nStageBars != pCStage->nStageBars || pSvdStage->iVar != pCStage->iVar || pSvdStage->idStyle != pCStage->idStyle || pSvdStage->aFills.size() != pCStage->aFills.size()) { return TRUE; } else { for (int j = 0; j < pCStage->aFills.size(); j++) { if (pSvdStage->aFills[j] != pCStage->aFills[j]) { return TRUE; } } } } } // 全曲音频 if (g_bSongNeedSave) { // 全曲小节音量 if (g_lstCompleteVols_SVD.size() != g_lstCompleteVols.size()) { return TRUE; } else { for (int i = 0; i < g_lstCompleteVols.size(); i++) { PBARVOLS pSvdBV = g_lstCompleteVols_SVD[i], pBV = g_lstCompleteVols[i]; if (pSvdBV->bRecording != pBV->bRecording || pSvdBV->bInvalid != pBV->bInvalid) { return TRUE; } else { for (int j = 0; j < POINTS_PER_BAR; j++) { if (pSvdBV->aVols[j] != pBV->aVols[j]) { return TRUE; } } } } } } //音效 for( int i=0; i 1) { g_strFontFile = (TCHAR*)szBuffer; } dwSize = MAX_PATH; lResult = RegQueryValueEx(hComposerKey, L"LastSaveFile", NULL, NULL, szBuffer, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 1) { g_strLastSaveFile = (TCHAR*)szBuffer; } dwSize = MAX_PATH; lResult = RegQueryValueEx(hComposerKey, L"ExtFontsDir", NULL, NULL, szBuffer, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 1) { g_strExtFontsPath = (TCHAR*)szBuffer; } int nValue; dwSize = sizeof(int); //add by tj 2013/12/30 lResult = RegQueryValueEx(hComposerKey, L"AutoSave", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bAutoSave = nValue; } lResult = RegQueryValueEx(hComposerKey, L"AutoOpenProject", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bAutoOpenProject = nValue; } lResult = RegQueryValueEx(hComposerKey, L"AutoOpenProjectEnable", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bAutoOpenProjectEnable = nValue; } lResult = RegQueryValueEx(hComposerKey, L"AutoDownloadStyle", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bAutoDownloadStyle = nValue; } lResult = RegQueryValueEx(hComposerKey, L"Prebeat", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bPrebeat = nValue; } lResult = RegQueryValueEx(hComposerKey, L"PreStageMode", NULL, &dwType, (LPBYTE) &nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { if( (0<=nValue) && (nValue<=2) ){ g_iPreStageDefault = nValue; }else{ g_iPreStageDefault= 2; } } lResult = RegQueryValueEx(hComposerKey, L"PreStyleSort", NULL, &dwType, (LPBYTE) &nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { if( ( ( 0 <= (nValue&0xffff) ) && ( (nValue&0xffff) <= 2 ) ) && ( ( 0 <= ( (nValue&0xffff0000)>>16 ) ) && ( ( (nValue&0xffff0000)>>16) <= 1) ) ) { g_iPreStyleSort = nValue; }else{ g_iPreStyleSort = STYLESORT_TIME | (STYLESORT_DOWN<<16); } } lResult = RegQueryValueEx(hComposerKey, L"TimeSignature", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { if( nValue<0 || nValue>3 ) nValue = 0; // SetMelodyTS( nValue ); g_iMelodyTimeSignature = nValue; } lResult = RegQueryValueEx(hComposerKey, L"Tempo", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { if( nValue<50 || nValue>200 ) nValue = 75; // SetMelodyTempo( nValue ); g_nMelodyTempo = nValue; } lResult = RegQueryValueEx(hComposerKey, L"PlaybackDevice", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iPlaybackDevice = nValue; } lResult = RegQueryValueEx(hComposerKey, L"PlaybackOutput", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iPlaybackOutput = nValue; } dwSize = MAX_PATH; lResult = RegQueryValueEx(hComposerKey, L"PlaybackDeviceName", NULL, NULL, szBuffer, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 1) { strcpy( g_strPlaybackDevice, szBuffer ); } lResult = RegQueryValueEx(hComposerKey, L"RecordDevice", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iRecordDevice = nValue; } lResult = RegQueryValueEx(hComposerKey, L"RecordInput", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iRecordInput = nValue; } dwSize = MAX_PATH; lResult = RegQueryValueEx(hComposerKey, L"RecordDeviceName", NULL, NULL, szBuffer, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 1) { strcpy( g_strRecordDevice, szBuffer ); } lResult = RegQueryValueEx(hComposerKey, L"RecordAutoAdjust", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bRecordAutoAdjust = nValue; } lResult = RegQueryValueEx(hComposerKey, L"LastSaveOption", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iLastSaveOption = nValue; } lResult = RegQueryValueEx(hComposerKey, L"WindowState", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iWindowState = nValue; } lResult = RegQueryValueEx(hComposerKey, L"LastSaveType", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iLastSaveType = nValue; } lResult = RegQueryValueEx(hComposerKey, L"ShowRecordHint", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bShowRecordHint = nValue ? true : false; } /* lResult = RegQueryValueEx(hComposerKey, L"APRActive", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bAPRActive = nValue ? true : false; } */ lResult = RegQueryValueEx(hComposerKey, L"ShowProtectMessage", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_bShowProtectMsg = nValue; } lResult = RegQueryValueEx(hComposerKey, L"ChordFontType", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { g_iShowType = nValue ? true : false; } float fValue; dwSize = sizeof(float); lResult = RegQueryValueEx(hComposerKey, L"RecordVolume", NULL, &dwType, (LPBYTE) & fValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { if( fValue<0 || fValue>1 ) fValue = 1; g_fRecordVolume = fValue; } lResult = RegQueryValueEx(hComposerKey, L"SpeakerVolume", NULL, &dwType, (LPBYTE) & fValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { if( fValue<0 || fValue>1 ) fValue = 1; g_fSpeakerVolume = fValue; } for (int i = 0; i < MAX_RECENT_PROJECT; i++) { wstring strValueName = L"RecentProject"; strValueName += IntToStr(i + 1).c_str(); dwSize = MAX_PATH; lResult = RegQueryValueEx(hComposerKey, strValueName.c_str(), NULL, NULL, szBuffer, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 1) { g_lstRecentProject.push_back((LPCTSTR)szBuffer); } } //mac address lResult = RegQueryValueEx(hComposerKey, L"deviceNum", NULL, &dwType, (LPBYTE) & nValue, &dwSize); if (lResult == ERROR_SUCCESS && dwSize>0 && nValue>0) { for(int index=0; index 0 && szBuffer[0]!=0) { g_lstMacAddress.push_back(szBuffer); }else{ SAFE_DELETE(szBuffer) } } } } RegCloseKey(hComposerKey); } } void SetAutoLogin(bool bAuto, LPCSTR strName, LPCSTR strPwd) { HKEY hComposerKey; DWORD dwDisposition; long lResult; lResult = RegCreateKeyEx(HKEY_CURRENT_USER, REGKEY_SOFTWARE, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hComposerKey, &dwDisposition); if (lResult == ERROR_SUCCESS) { BYTE strText[100]; int nNameLen = strlen(strName), nRegLen = nNameLen + 1; strText[0] = nNameLen; for (int i = 0; i < nNameLen; i++) { strText[i + 1] = strName[i] - 0x63; } strText[nNameLen + 1] = '\0'; if (bAuto) { int nMaxPwdLen = 16, nPwdLen = strlen(strPwd); strText[nNameLen + 1] = nPwdLen; for (int i = 0; i < nMaxPwdLen; i++) { if (i < nPwdLen) strText[i + nNameLen + 2] = strPwd[i] - 0x4B; else strText[i + nNameLen + 2] = Random(256); } strText[nNameLen + nMaxPwdLen + 2] = '\0'; nRegLen += 17; } lResult = RegSetValueEx(hComposerKey, REGKEY_AUTOLOG, 0, REG_BINARY, strText, nRegLen); RegCloseKey(hComposerKey); } } bool GetAutoLogin(char* strName, char* strPwd) { HKEY hComposerKey; DWORD dwDisposition; bool bAuto = false; strName[0] = strPwd[0] = 0; long lResult = RegCreateKeyEx(HKEY_CURRENT_USER, REGKEY_SOFTWARE, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hComposerKey, &dwDisposition); if (lResult == ERROR_SUCCESS) { DWORD dwSize; BYTE szBuffer[MAX_PATH]; if (dwDisposition == REG_OPENED_EXISTING_KEY) { dwSize = MAX_PATH; lResult = RegQueryValueEx(hComposerKey, REGKEY_AUTOLOG, NULL, NULL, szBuffer, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 0) { int nTextLen = dwSize; int nNameLen = szBuffer[0]; for (int i = 0; i < nNameLen; i++) { strName[i] = szBuffer[i + 1] + 0x63; } strName[nNameLen] = '\0'; if (nNameLen == nTextLen - 18) { bAuto = true; int nPwdLen = szBuffer[nNameLen + 1]; for (int i = 0; i < nPwdLen; i++) { strPwd[i] = szBuffer[i + nNameLen + 2] + 0x4B; } strPwd[nPwdLen] = '\0'; } } } RegCloseKey(hComposerKey); } return bAuto; } void GetAutoSaveReg() { HKEY hComposerKey; DWORD dwDisposition; long lResult; lResult = RegCreateKeyEx(HKEY_CURRENT_USER, REGKEY_SOFTWARE, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hComposerKey, &dwDisposition); if (lResult == ERROR_SUCCESS) { if (dwDisposition == REG_OPENED_EXISTING_KEY) { DWORD dwSize = MAX_PATH; BYTE szBuffer[MAX_PATH]; lResult = RegQueryValueEx(hComposerKey, L"AutoSaveProj", NULL, NULL, szBuffer, &dwSize); if (lResult == ERROR_SUCCESS && dwSize > 1) { g_strProjectName = (TCHAR*)szBuffer; } } RegCloseKey(hComposerKey); } } void SetAutoSaveReg() { HKEY hComposerKey; DWORD dwDisposition; long lResult; lResult = RegCreateKeyEx(HKEY_CURRENT_USER, (TCHAR*)REGKEY_SOFTWARE, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hComposerKey, &dwDisposition); if (lResult == ERROR_SUCCESS) { DWORD dwValue = g_bAutoSave; lResult = RegSetValueEx(hComposerKey, L"AutoSave", 0, REG_DWORD, (LPBYTE) & dwValue, sizeof(DWORD)); lResult = RegSetValueEx(hComposerKey, L"AutoSaveProj", 0, REG_SZ, (LPBYTE)g_strProjectName.c_str(), g_strProjectName.length()*sizeof(WCHAR) + 1); RegCloseKey(hComposerKey); } } void ClearAutoProj() { g_bAutoSave = false;//add by tj 2014/02/27 SetAutoSaveReg(); if( FileExists( g_strAutoProjName.c_str() ) ) DeleteFile( g_strAutoProjName.c_str() ); DebugPrint("delete auto Save project file...."); } void SaveAutoProj() { DebugPrint("auto Save project...."); // String strPath = g_strExecutePath.c_str(); // strPath += _T(AUTOSAVE_FILENAME); if( HasProjectModified() ){ AnsiString strProjectName = g_strAutoProjName.c_str(); SaveProject( strProjectName.c_str(), PROJ_MODE_AUTO); } } bool ReloadBaseCompose() { bool bRet = true; BOOL bModified = g_bkMelody.CheckModified(); if( bModified ){ bRet = GenerateBaseCompose(); if( bRet ){ g_bkMelody.Backup(); } } return bRet; } bool GenerateBaseCompose() { HRESULT hr = S_FALSE; int nBufferLength, nStageNum = 0, nChordsNum = 0, nFillNum = 0, nMelodyBarNum = g_lstMelodyBars.size(); int(*aStages)[2], (*aChords)[2], (*aFills)[2]; aFills = new int[nMelodyBarNum][2]; aChords = new int[nMelodyBarNum * 2][2]; for (int i = 0; i < nMelodyBarNum; i++) { MELODYBAR *pBar = g_lstMelodyBars[i]; if (pBar->iFill != -1) { aFills[nFillNum][0] = i; aFills[nFillNum][1] = pBar->iFill; nFillNum++; } if (pBar->iChords[0] != -1) { aChords[nChordsNum][0] = ((pBar->iChords[0] / CHORD_TYPE_NUM + g_iMelodyKey) % KEY_NUM) * CHORD_TYPE_NUM + pBar->iChords[0] % CHORD_TYPE_NUM; aChords[nChordsNum][1] = 0; if (pBar->iChords[1] == -1) { aChords[nChordsNum][1] = 1; } else { nChordsNum++; aChords[nChordsNum][0] = ((pBar->iChords[1] / CHORD_TYPE_NUM + g_iMelodyKey) % KEY_NUM) * CHORD_TYPE_NUM + pBar->iChords[1] % CHORD_TYPE_NUM; aChords[nChordsNum][1] = 0; } nChordsNum++; } } DebugPrint("//////////////////和弦输出/////////////////////"); for (int i = 0; i < nChordsNum; i++) { DebugPrint(" %d %d", aChords[i][0], aChords[i][1]); } DebugPrint("//////////////////分段输出/////////////////////"); nStageNum = g_lstMelodyStages.size(); if (nStageNum > 0) { aStages = new int[nStageNum][2]; for (int i = 0; i < nStageNum; i++) { MELODYSTAGE* pStage = g_lstMelodyStages[i]; aStages[i][0] = pStage->iLastBar; aStages[i][1] = pStage->iVar; DebugPrint(" %d - %d", aStages[i][0], aStages[i][1]); } } else { aStages = new int[nMelodyBarNum][2]; } DebugPrint("MF_Basecompose StyleID=%d", g_iSelectedStyleID); BYTE * pBuffer = new BYTE[1000000]; nBufferLength = 1000000; int ret = f_SM_BaseCompose(g_iMelodyKey, &nBufferLength, pBuffer, &nStageNum, aStages, &nChordsNum, aChords, &nFillNum, aFills, g_iSelectedStyleID); if (ret==0) { DebugPrint("Basecompose return buffer size = %d.\n", nBufferLength); if (g_lstMelodyStages.size() == 0) { DebugPrint("//////////////////分段输入/////////////////////"); if (nStageNum > 0) { int iFirstStageBar = 0; for (int i = 0; i < nStageNum; i++) { MELODYSTAGE* pStage = new MELODYSTAGE; pStage->iFirstBar = iFirstStageBar; pStage->iLastBar = aStages[i][0]; pStage->iVar = aStages[i][1]; g_lstMelodyStages.push_back(pStage); iFirstStageBar = aStages[i][0] + 1; DebugPrint(" %d - %d", aStages[i][0], aStages[i][1]); } } } if (nFillNum > 0) { for (int i = 0; i < nFillNum; i++) { MELODYBAR *pBar = g_lstMelodyBars[aFills[i][0]]; pBar->iFill = aFills[i][1]; } } DebugPrint("//////////////////和弦输入/////////////////////"); if (nChordsNum > 0) { int index = 0; for (int i = 0; i < nChordsNum; i++) { int iKey = aChords[i][0] / CHORD_TYPE_NUM; if (iKey >= g_iMelodyKey) iKey -= g_iMelodyKey; else iKey += KEY_NUM - g_iMelodyKey; MELODYBAR *pBar = g_lstMelodyBars[index]; pBar->iChords[0] = iKey * CHORD_TYPE_NUM + aChords[i][0] % CHORD_TYPE_NUM; if (aChords[i][1] == CHORD_WHOLE_BAR) { pBar->iChords[1] = -1; } else { i++; iKey = aChords[i][0] / CHORD_TYPE_NUM; if (iKey >= g_iMelodyKey) iKey -= g_iMelodyKey; else iKey += KEY_NUM - g_iMelodyKey; pBar->iChords[1] = iKey * CHORD_TYPE_NUM + aChords[i][0] % CHORD_TYPE_NUM; } index++; DebugPrint(" %d %d", pBar->iChords[0], pBar->iChords[1]); } } hr = f_MM_LoadBaseCompose(pBuffer, nBufferLength); if (FAILED(hr)) { DebugPrint("Load base compose error. errcode = %x\n", hr); } else { f_MM_SetStreamVolume(3, g_fMusicVolume); DebugPrint("Load base compose complete.\n"); g_bBaseComposeLoaded = true; SaveAutoProj(); } } else { DebugPrint("Base compose error.\n"); } SAFE_DELETE_ARRAY(pBuffer); SAFE_DELETE_ARRAY(aFills); SAFE_DELETE_ARRAY(aChords); SAFE_DELETE_ARRAY(aStages); return hr == S_OK; } bool UpdateStageBars() { bool bBarChanged = false; for( int i=0; iidStyle==g_iSelectedStyleID ){ if( pCStage->iMelodyStage>=COMPOSE_ENDING_1 ){ int iEnding = pCStage->iMelodyStage - COMPOSE_ENDING_1; if( pCStage->nStageBars!=g_arrEndingBarNum[iEnding] ){ bBarChanged = true; if( g_arrEndingBarNum[iEnding]<=0 ){ pCStage->iMelodyStage = COMPOSE_ENDING_1; } pCStage->nStageBars = g_arrEndingBarNum[iEnding]; } } else if( pCStage->iMelodyStage>=COMPOSE_INTRO_1 ){ int iIntro = pCStage->iMelodyStage - COMPOSE_INTRO_1; if( pCStage->nStageBars!=g_arrIntroBarNum[iIntro] ){ bBarChanged = true; if( g_arrIntroBarNum[iIntro]<=0 ){ pCStage->iMelodyStage = COMPOSE_INTRO_1; } pCStage->nStageBars = g_arrIntroBarNum[iIntro]; } } } } return bBarChanged; } bool UpdateSegmentBars() { bool bStyleChanged = ( g_iLastStyleID!=g_iSelectedStyleID ); if( bStyleChanged ){ memset( g_arrIntroBarNum, 0, MAX_INTRO_NUM*sizeof(int) ); memset( g_arrEndingBarNum, 0, MAX_ENDING_NUM*sizeof(int) ); bool bUseful = f_SM_CheckStyle( g_iSelectedStyleID ); if( bUseful ){ for( int i=0; iidStyle==g_iLastStyleID ){ pCStage->idStyle = g_iSelectedStyleID; } } g_iLastStyleID = g_iSelectedStyleID; } } return bStyleChanged; } void InitComposeStage() { MELODYSTAGE *pMStage = NULL; COMPOSESTAGE* pCStage = NULL; //初始化曲式段落,缺省为 Intro1 + 全部旋律段 + Intro2 + 全部旋律段 + Ending1 bool bWeakupBar = g_bWeakup && ( g_lstMelodyStages[0]->iLastBar==0 ); int iFirstStage = bWeakupBar ? 1 : 0; int nCount = g_iPreStageDefault; for( int i=0; i0 ){ pCStage = new COMPOSESTAGE; pCStage->iMelodyStage = COMPOSE_INTRO_1 + i; pCStage->nStageBars = g_arrIntroBarNum[i]; pCStage->idStyle = g_iSelectedStyleID; g_lstComposeStages.push_back( pCStage ); } for( int j=iFirstStage; jiMelodyStage = j; pCStage->nStageBars = pMStage->iLastBar - pMStage->iFirstBar + 1; pCStage->iVar = pMStage->iVar; pCStage->idStyle = g_iSelectedStyleID; for( int k=pMStage->iFirstBar; k<=pMStage->iLastBar; k++ ){ MELODYBAR *pMBar = g_lstMelodyBars[k]; if( pMBar->iFill!=-1 ){ DWORD dwFill = MAKELONG( k - pMStage->iFirstBar, pMBar->iFill ); pCStage->aFills.push_back( dwFill ); } else if( k==pMStage->iLastBar ){ DWORD dwFill = k - pMStage->iFirstBar; pCStage->aFills.push_back( dwFill ); } } g_lstComposeStages.push_back( pCStage ); } // if( i==nCount-1 ) break; } if( g_iPreStageDefault && g_arrEndingBarNum[0]>0 ){ pCStage = new COMPOSESTAGE; pCStage->iMelodyStage = COMPOSE_ENDING_1; pCStage->nStageBars = g_arrEndingBarNum[0]; pCStage->idStyle = g_iSelectedStyleID; g_lstComposeStages.push_back( pCStage ); } } int GetComposeData( COMPOSESTAGELIST lstComposeStages, int iKey, int& nDataSize, LPBYTE lpData, bool bCombineSong, int& nTimeSet, double (*aTimeSet)[2] ) { int nMelodyStageNum = 0, nChordsNum = 0, nComposeStageNum = 0, nFillNum = 0, nComplementNum = 0, nVolSetNum = 0, nInsSetNum = 0; int(*aMelodyStages)[2] = NULL, (*aComposeStages)[2] = NULL, (*aChords)[2] = NULL, *aStyleID = NULL, (*aFills)[2] = NULL, (*aComplements)[2] = NULL, (*aVolSets)[3] = NULL, (*aInsSets)[3] = NULL; DebugPrint("//////////////////曲式分段输出/////////////////////"); vectorarrFillPos, arrFillType, arrComplementCPos, arrComplementMPos; nComposeStageNum = lstComposeStages.size(); if (nComposeStageNum > 0) { int iFirstBar = 0; aComposeStages = new int[nComposeStageNum][2]; aStyleID = new int[nComposeStageNum]; for (int i = 0; i < nComposeStageNum; i++) { COMPOSESTAGE* pComposeStage = lstComposeStages[i]; aComposeStages[i][0] = pComposeStage->iMelodyStage; aComposeStages[i][1] = pComposeStage->iVar; if (bCombineSong) { // 拼接旋律/////////////////////////////////////// if (pComposeStage->iMelodyStage < COMPOSE_INTRO_1) { MELODYSTAGE * pMStage = g_lstMelodyStages[pComposeStage->iMelodyStage]; aTimeSet[nTimeSet][0] = pMStage->iFirstBar; } else { aTimeSet[nTimeSet][0] = -1; } if( nTimeSet>0 && aTimeSet[nTimeSet-1][0]>=0 && lstComposeStages[i-1]->iMelodyStage ==pComposeStage->iMelodyStage-1 ){ aTimeSet[nTimeSet-1][1] += pComposeStage->nStageBars; } else if( nTimeSet>0 && g_bWeakup && pComposeStage->iMelodyStage==1 && aTimeSet[nTimeSet-1][0]==-1 ){ aTimeSet[nTimeSet - 1][1] -= 0.5; aTimeSet[nTimeSet][0] -= 0.5; aTimeSet[nTimeSet][1] = pComposeStage->nStageBars + 0.5; nTimeSet++; } else { aTimeSet[nTimeSet][1] = pComposeStage->nStageBars; nTimeSet++; } ///////////////////////////////////////////////// } aStyleID[i] = pComposeStage->idStyle; for (int j = 0; j < pComposeStage->aFills.size(); j++) { int iPos = LOWORD(pComposeStage->aFills[j]), iType = HIWORD(pComposeStage->aFills[j]); arrFillPos.push_back(iPos + iFirstBar); arrFillType.push_back(iType); } if (pComposeStage->iMelodyStage >=COMPOSE_INTRO_1 && pComposeStage->iVar == 1) { // 补足主旋律 arrComplementCPos.push_back(iFirstBar); arrComplementMPos.push_back( g_lstMelodyStages[lstComposeStages[i-1]->iMelodyStage+1]->iFirstBar); } iFirstBar += pComposeStage->nStageBars; DebugPrint(" %x - %d - %d", aComposeStages[i][0], aComposeStages[i][1], aStyleID[i]); } } DebugPrint("//////////////////补足主旋律输出/////////////////////"); nComplementNum = arrComplementCPos.size(); if (nComplementNum > 0) { aComplements = new int[nComplementNum][2]; for (int i = 0; i < nComplementNum; i++) { aComplements[i][0] = arrComplementCPos[i]; aComplements[i][1] = arrComplementMPos[i]; DebugPrint(" %d - %d", aComplements[i][0], aComplements[i][1]); } } DebugPrint("//////////////////加花输出/////////////////////////"); nFillNum = arrFillPos.size(); if (nFillNum > 0) { aFills = new int[nFillNum][2]; for (int i = 0; i < nFillNum; i++) { aFills[i][0] = arrFillPos[i]; aFills[i][1] = arrFillType[i]; DebugPrint(" %d - %d", aFills[i][0], aFills[i][1]); } } DebugPrint("//////////////////旋律分段输出/////////////////////"); nMelodyStageNum = g_lstMelodyStages.size(); if (nMelodyStageNum > 0) { aMelodyStages = new int[nMelodyStageNum][2]; for (int i = 0; i < nMelodyStageNum; i++) { MELODYSTAGE* pMelodyStage = g_lstMelodyStages[i]; aMelodyStages[i][0] = pMelodyStage->iLastBar; aMelodyStages[i][1] = pMelodyStage->iVar; DebugPrint(" %d - %d", aMelodyStages[i][0], aMelodyStages[i][1]); } } DebugPrint("//////////////////和弦输出/////////////////////"); int nMelodyBarNum = g_lstMelodyBars.size(); aChords = new int[nMelodyBarNum * 2][2]; for (int i = 0; i < nMelodyBarNum; i++) { MELODYBAR *pBar = g_lstMelodyBars[i]; if (pBar->iChords[0] != -1) { aChords[nChordsNum][0] = ((pBar->iChords[0] / CHORD_TYPE_NUM + iKey) % KEY_NUM) * CHORD_TYPE_NUM + pBar->iChords[0] % CHORD_TYPE_NUM; aChords[nChordsNum][1] = 0; if (pBar->iChords[1] == -1) { aChords[nChordsNum][1] = 1; } else { nChordsNum++; aChords[nChordsNum][0] = ((pBar->iChords[1] / CHORD_TYPE_NUM + iKey) % KEY_NUM) * CHORD_TYPE_NUM + pBar->iChords[1] % CHORD_TYPE_NUM; aChords[nChordsNum][1] = 0; } nChordsNum++; } } for (int i = 0; i < nChordsNum; i++) { DebugPrint(" %d %d", aChords[i][0], aChords[i][1]); } int ret = f_SM_Compose(iKey, &nDataSize, lpData, nMelodyStageNum, aMelodyStages, nChordsNum, aChords, nComposeStageNum, aComposeStages, aStyleID, nFillNum, aFills, nComplementNum, aComplements, nVolSetNum, aVolSets, nInsSetNum, aInsSets); DebugPrint("Compose return buffer size = %d.\n", nDataSize); SAFE_DELETE_ARRAY(aStyleID); SAFE_DELETE_ARRAY(aMelodyStages); SAFE_DELETE_ARRAY(aComposeStages); SAFE_DELETE_ARRAY(aChords); SAFE_DELETE_ARRAY(aFills); SAFE_DELETE_ARRAY(aComplements); SAFE_DELETE_ARRAY(aVolSets); SAFE_DELETE_ARRAY(aInsSets); return ret; } bool IsProtected() { if( g_bLogon && g_infoUser.accountInfo.vipPeriod!=0 ) return false; //未付费风格检测 vector aStyleID; for( int i=0; iidStyle ){ bChecked = true; break; } } if( !bChecked ){ bool bPaied = false; if( g_bLogon ){ for( int k=0; kidStyle ){ bPaied = true; break; } } } if( !bPaied ){ TSTYLEINFO infoStyle; f_SM_GetStyleInfo( pStage->idStyle, &infoStyle ); if( infoStyle.cost>0 ){ return true; } } aStyleID.push_back( pStage->idStyle ); } } return false; } bool ReloadCompose(int iKey) { bool bRet = true; BOOL bModified = g_bkCompose.CheckModified(); if( iKey!=g_bkCompose.m_iKey || bModified ){ bRet = GenerateCompose( iKey, !g_bSongNeedSave ); g_bkCompose.Backup( iKey ); //g_bSongSaved = false; g_strMP3File = ""; } return bRet; } bool GenerateCompose(int iKey, bool bCombineSong) { HRESULT hr; int nTimeSet = 0; double(*aTimeSet)[2] = new double[g_lstComposeStages.size()][2]; BYTE* pBuffer = new BYTE[2000000]; int nBufferLength = 2000000; int ret = GetComposeData( g_lstComposeStages, iKey, nBufferLength, pBuffer, bCombineSong, nTimeSet, aTimeSet ); if (ret==0) { hr = f_MM_LoadCompose(pBuffer, nBufferLength); if( hr==S_FALSE ) { DebugPrint("Load compose error. errcode = %x\n", hr); } else { g_bRecProtect = IsProtected(); f_MM_SetRecordProtect( g_bRecProtect ); f_MM_SetStreamVolume(4, g_fMusicVolume); g_bComposeLoaded = true; SaveAutoProj(); DebugPrint("Load compose complete.\n"); } if (nTimeSet > 0) { hr = f_MM_CombineSong( nTimeSet, aTimeSet ); if (hr != S_OK) { DebugPrint("Load song error. errcode = %x\n", hr); } else { f_MM_SetStreamVolume(5, g_fAudioVolume); g_bSongLoaded = true; } } } else { DebugPrint("Compose error.\n"); } SAFE_DELETE_ARRAY(pBuffer); SAFE_DELETE_ARRAY(aTimeSet); return hr == S_OK; } void ResetAudioEffects() { //重置音效,混响/APR缺省开启 for( int i=0; iClassNameIs( TLabel::ClassName() ) ){ TLabel* pC = (TLabel*)pCtrl; pC->ControlStyle = pC->ControlStyle>>csOpaque; } else if( pCtrl->ClassNameIs( TCheckBox::ClassName() ) ){ ((TCheckBox*)pCtrl)->Color = RGB(230, 204, 179); } else if( pCtrl->ClassNameIs( TRadioButton::ClassName() ) ){ ((TRadioButton*)pCtrl)->Color = RGB(230, 204, 179); } else{ for( int i=0; iComponentCount; i++ ){ SetTransparent( pCtrl->Components[i] ); } } } void UniDrawChord(TCanvas *Canvas, TRect rcDraw, int iMainKey, int iAjustKey, int iType) { String strMainKey, strAjustKey, strA, strN; if( iAjustKey==1 ) strAjustKey = L"#"; else if( iAjustKey==-1 ) strAjustKey = L"b"; if( iType==1 || iType==3 ) strA = L"m"; if( iType==2 || iType==3 ) strN = L"7"; int iMKeyLeft, iATypeLeft, iNTypeLeft, wChord(0), wMKey(12), wAKey(3), wType(8), wVKey(12), wIKey(6); if( !g_iShowType ){ //罗马字母 if( iMainKey==0 ){ wMKey = iType>0 ? 6 : 8; } else if( iMainKey==1 ){ wMKey = iType>0 ? 12 : 16; } else if( iMainKey==2 ){ wIKey = 5; wMKey = iType>0 ? 16 : 18; } else if( iMainKey==3 ){ wVKey = 11; wMKey = iType>0 ? 15 : 18; } else if( iMainKey==4 ){ wMKey = iType>0 ? 10 : 16; } else if( iMainKey==5 ){ wVKey = 11; wIKey = 5; wMKey = iType>0 ? 17 : 20; } else if( iMainKey==6 ){ wVKey = 11; wIKey = 5; wMKey = iType>0 ? 22 : 26; } } else{ //英文字母 if( iMainKey==5 ){ //A升降号靠近 wAKey = 1; } else if( iMainKey==3 ){ //F下标靠近 wMKey = 9; } } wChord += wMKey; if( iAjustKey!=0 ) wChord += wAKey; if( strA.Length()>0 ) wChord += wType - 1; if( strN.Length()>0 ) wChord += wType - 1; int iLeft = rcDraw.Left + ( rcDraw.Width() - wChord ) / 2, iOriTop = rcDraw.top + (rcDraw.Height() - 18) / 2; TFont *fntOld = new TFont; fntOld->Assign( Canvas->Font ); Canvas->Font->Name = "Times New Roman"; Canvas->Font->Quality = TFontQuality::fqClearTypeNatural; Canvas->Font->Color = RGB(60,43,23); Canvas->Font->Style = TFontStyles()<Brush->Style = bsClear; //绘制升降调 if( iAjustKey!=0 ){ int iTop = iOriTop-2; if( iAjustKey==-1 || !g_iShowType && iMainKey==6 ) iTop++; Canvas->Font->Size = g_szFont8; //升降字体大小 Canvas->TextOut( iLeft, iTop, strAjustKey ); iLeft += wAKey; } int iTop = iOriTop - 1; Canvas->Font->Size = g_szFont16; //和弦字体大小 if( g_iShowType ){ strMainKey = u_strAlphaTable[iMainKey]; Canvas->TextOut( iLeft, iTop, strMainKey ); } else{ int l = iLeft; if( iMainKey<4 ){ strMainKey = L"I"; Canvas->TextOut( l, iTop, strMainKey ); l += wIKey; if( iMainKey==3 ){ strMainKey = L"V"; Canvas->TextOut( l, iTop, strMainKey ); l += wVKey; } else if( iMainKey>0 ){ Canvas->TextOut( l, iTop, strMainKey ); l += wIKey; if( iMainKey==2 ){ Canvas->TextOut( l, iTop, strMainKey ); l += wIKey; } } } else{ strMainKey = L"V"; Canvas->TextOut( l, iTop, strMainKey ); l += wVKey; if( iMainKey>4 ){ strMainKey = L"I"; Canvas->TextOut( l, iTop, strMainKey ); l += wIKey; if( iMainKey==6 ){ Canvas->TextOut( l, iTop, strMainKey ); l += wIKey; } } } } iLeft += wMKey; iTop = iOriTop + 6; //绘制A if( strA.Length()>0 ){ Canvas->Font->Size = g_szFont9; Canvas->TextOut( iLeft+2, iTop, strA ); iLeft += wType; } //绘制N if( strN.Length()>0 ){ iTop += g_szFont8==g_szFont9 ? 2 : 3; Canvas->Font->Size = g_szFont8; Canvas->Font->Style = TFontStyles(); Canvas->TextOut( iLeft+4, iTop, strN ); } Canvas->Font->Assign( fntOld ); delete fntOld; } char* GetMacAdress() { //首先选择原用mac if(!g_lstMacAddress.empty()) return g_lstMacAddress[0]; //查找本地mac // PIP_ADAPTER_INFO pIpAdapterInfo = new IP_ADAPTER_INFO(); // unsigned long stSize = sizeof(IP_ADAPTER_INFO); // int nRes = GetAdaptersInfo(pIpAdapterInfo, &stSize); // // if( ERROR_BUFFER_OVERFLOW==nRes ){ // SAFE_DELETE(pIpAdapterInfo) // pIpAdapterInfo = (PIP_ADAPTER_INFO)new BYTE[stSize]; // nRes=GetAdaptersInfo(pIpAdapterInfo, &stSize); // } // // if( ERROR_SUCCESS==nRes ){ // char zeroBuf[6] = {0}; // while( pIpAdapterInfo ){ // char *idDevice = new char[6]; // for(int index=0; indexAddressLength; index++) // idDevice[index] = pIpAdapterInfo->Address[index]; // // if(memcmp(idDevice, zeroBuf, 6)) // g_lstMacAddressNew.push_back(idDevice); // // pIpAdapterInfo = pIpAdapterInfo->Next; // } // } // SAFE_DELETE(pIpAdapterInfo) // int nEqualIndex = -1; // for(int indexNew=0; indexNew=0 ) { // for(int i=0; i