Files
2026-09-13 11:54:43 +08:00

539 lines
20 KiB
C++

// ---------------------------------------------------------------------------
#ifndef GlobalUnitH
#define GlobalUnitH
#include "commonstruct.h"
#include "MessageDef.h"
// ---------------------------------------------------------------------------
/*************************************************************************************** /
// 全局定义
/************************************************************************************** */
#define APPNAME "魔方风格工具\0"
#define SOFTWARE_ID e_SM_Checker
#define MINUM_COLUMN 5
#define MINUM_ROW 6
#define MAX_PATH 260
#define DLLAPI __stdcall
#define CELL_ABSORB_WIDTH 10
#define CHORD_WHOLE_BAR 1
#define CHORD_HALF_BAR 0
#define ID_INITIAL_BAR 1
#define CHORD_TYPE_NUM 4
#define KEY_NUM 12
#define MAX_INTRO_NUM 4
#define MAX_ENDING_NUM 4
#define COMPOSE_FILL_NUM 2
#define STAGE_VAR_NUM 4
#define LIST_MELODYBARS 0x01
#define LIST_MELODYCHORDS 0x02
#define LIST_MELODYSTAGES 0x04
#define LIST_COMPOSESTAGES 0x08
#define LIST_COMPLETEVOLS 0x10
#define LIST_ALL 0x1F
#define TIMER_ACCURACY 1
#define TIMER_PLAY_INTERVAL 25
#define TIME_HINT 500
#define CHANNEL_MELODY 0
#define MELODY_DEF_VOLUMN 90
#define MIDI_EVENT_INSTRUMENT 2
#define MIDI_EVENT_VOLUME 12
#define SAFE_FREE(p) { if(p) { free(p); (p)=NULL; } }
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#define SEGTYPE_VAR 0
#define SEGTYPE_FILL 1
#define SEGTYPE_INTRO 2
#define SEGTYPE_ENDING 3
#define TYPE_BASECOMPOSE 0x01
#define TYPE_COMPOSE 0x02
#define TYPE_AUDIO 0x04
#define TYPE_SONG 0x08
#define TYPE_BEAT 0x10
#define TYPE_AUDIO_BASECOMPOSE 0x05
#define TYPE_SONG_COMPOSE 0x0A
#define TYPE_LOOPPLAY 0x200
#define FONT_SF2 0x10000
// 界面消息
#define UM_RESTORE WM_USER + 0x1000
#define UM_LOGIN WM_USER + 0x1004
#define REGKEY_SOFTWARE L"SOFTWARE\\iChangzuo\\StyleTools"
#define REGKEY_ACPRO L"SOFTWARE\\iChangzuo\\AC_Pro"
#define REGKEY_AUTOLOG L"{0DF44EAA-FF21-4412-828E-250A8728E7F1}"
#define REGKEY_INSTALDIR L"InstallDir"
/*************************************************************************************** /
// 全局常量
/************************************************************************************** */
extern const DWORD g_dwProjectVersion;
extern const char * LSZ_STYLTYPES[];
extern const char * LSZ_LIST_HEADS[];
extern const TColor g_clrSegment[4][8];
/*************************************************************************************** /
// 全局变量
/************************************************************************************** */
#include <vector>
using namespace std;
struct FONTINFO {
char strFileName[256];
char strFontName[80];
char strCopyright[128];
char strComment[256];
};
extern TMAKESTYLEINFO g_infoAuthor; // 作者相关信息
//extern FILENAMES g_infoFiles; // 文件路径信息
//extern TSTYLEINFO g_tpInfoAuthor; // 临时作者相关信息
//extern FILENAMES g_tpInfoFiles; // 临时文件路径信息
extern wstring g_strFontPath, // 音色库路径
g_strFontFile, // 音色库文件名
g_strExecutePath, // 执行文件路径
g_strProjectName; // 工程文件名
extern vector<wstring>g_lstRecentProject; // 最近的工程文件
extern HANDLE g_hProjectEvent; // 工程文件读写互斥变量
extern string g_strSelectedStyleName; // 选中风格名
extern vector<int>g_lstStyleSelected; // 选中风格类型集合
extern DWORD g_iSelectedStyleType; // 选定风格类型
extern char g_strCurrentVersion[20], g_strServerURL[256];
extern int g_iSelectedStyleID, // 选定风格ID
g_idFont, // 选定音色库序号
g_iMelodyKey, // 主旋律调号
g_iComposeKey, // 伴奏调号,用于录音升降调
g_iMelodyTimeSignature, // 主旋律拍号
g_nMelodyTempo; // 主旋律速度
extern double g_dblStep, // 播放步长
g_dblTimePerBar; // 每小节时间(毫秒)
extern bool g_bRecreator;
/*************************************************************************************** /
// 全局函数
/************************************************************************************** */
/////////////////////////////////////////////////////////////////////////////////////////
// 风格处理函数段
//
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI int (*CM_Initialize)();
//函数名: Initialize
//功 能: 模块初始化
//返 回 值: 成功返回0, 否则返回错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI int (*CM_Release)();
//功 能:释放对象
//输 入:无
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI int (*CM_Clear)();
//功 能:清除数据
//输 入:无
//返回值:错误号
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*CM_Compose)( int* buffLen, BYTE buffer[], int ts, int tempo,
int nStageNum, void* aStages,
bool bSave, int* lenNotes, BYTE notes[] );
//函数名: Compose
//功 能: 按指定曲式结构编曲
//输 入:
// buffLen
// buffer 块内存地址
// ts/tempo指定节拍速度
// nStageNum 曲式分段数
// aStages 曲式分段数组 TStage类型
// bSave 用于播放/保存
// lenNotes/notes 获取轨道音符的长度/地址
//返 回: 成功返回0, 否则返回错误号
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (* CM_MakeStyle)( UINT idStyle, TMAKESTYLEINFO *pStyleInfo,
int &nBufferLen, BYTE* pBuffer );
//函数功能: 生成风格文件.
//参 数:
// idStyle 临时风格ID
// stAuthorInfo 相关信息
// nBufferLen 返回风格文件长度
// pBuffer 接收风格文件数据的缓冲区,外部分配,外部释放
//返 回 值: 成功返回0, 否则返回错误号
/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*CM_RecombineFiles)( UINT idStyle, char* commonName, int *pTS, int *pTempo );
// 函数功能: 重新合成文件
// 参 数:
// idStyle 临时风格ID
// commonName 文件名共同
// iTS 返回节拍
// nTempo 返回速度,
// 返 回 值: 成功返回0,否则返回-1
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*CM_GetSegmentInfo)( UINT idLoc, UINT idStyle, char info[4][8][2][2] );
// 函数功能: 获取临时风格片段信息
// 参 数:
// idLoc/idStyle 临时风格ID
// info[sType][sNo][cType][0] = bars
// info[sType][sNo][cType][1] = tracks
//返 回 值: 成功返回0, 否则返回错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI int (*CM_GetTracksInfo)( UINT idLoc, UINT idStyle, char sType, char sNo, char cType, char track[16][3] );
// 函数功能: 获取片段轨道信息
// 参 数:
// idLoc/idStyle 临时风格ID
// sType/sNo/cType 指定片段
// track[][0] = 通道号
// track[][1] = 乐器号
// track[][2] = 音量
//返 回 值: 成功返回track数
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI int (*CM_DeleteTrack)( UINT idStyle, char sType, char sNo, char cType, char chan );
// 函数功能: 删除轨道
// 参 数:
// idStyle 临时风格ID
// sType/sNo/chan 指定轨道
//返 回 值: 成功返回0,否则返回错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*CM_GetStyleInfo)( UINT idLoc, UINT idStyle, TPROSTYLE* tStyle );
//函数名: GetStyleInfo
//功 能: 获取指定ID的信息
//输 入:
//返 回: 成功返回0,否则为错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*CM_GetStyleInfos)( int iType, int iTS, TPROSTYLE aStyleInfos[], int *nInfoNum );
//函数名: GetStyleInfos
//功 能: 获取指定节拍的风格信息列表
//输 入:
// iType 风格类别 1=发布 2=本地 3=分享
//返 回: 成功返回0,否则为错误号
/////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------------------------
typedef DLLAPI HRESULT (*CM_GenerateCheckData)( UINT idLoc, UINT idStyle );
// 函数功能: 生成风格检查信息
// 参 数:
// idLoc/idStyle 风格ID
//返 回 值: 成功返回0, 否则返回错误号
//---------------------------------------------------------------------------------------------
typedef DLLAPI HRESULT (*CM_CompareStyle)( UINT idLoc, UINT idStyle, UINT check[2][4][2][5][2],
HWND hProcessWnd );
// 函数功能: 获取风格比对信息
// 参 数:
// idLoc/idStyle 风格ID
// check 比对结果 [s][n][c][i][0]=id, [s][n][c][i][1]=posibility + s<<16 + n<<24
// hProcessWnd 进度窗口 NULL=取数据
//返 回 值: 成功返回0, 否则返回错误号
extern CM_Initialize f_CM_Initialize;
extern CM_Release f_CM_Release;
extern CM_Clear f_CM_Clear;
extern CM_Compose f_CM_Compose;
extern CM_RecombineFiles f_CM_RecombineFiles;
extern CM_GetSegmentInfo f_CM_GetSegmentInfo;
extern CM_GetTracksInfo f_CM_GetTracksInfo;
extern CM_MakeStyle f_CM_MakeStyle;
extern CM_DeleteTrack f_CM_DeleteTrack;
extern CM_GetStyleInfo f_CM_GetStyleInfo;
extern CM_GetStyleInfos f_CM_GetStyleInfos;
extern CM_GenerateCheckData f_CM_GenerateCheckData;
extern CM_CompareStyle f_CM_CompareStyle;
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
// MediaModule函数段
//
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_InitialObjects) ( HWND hWnd, char* strRoot );
//功 能:初始化DirectMusic对象
//输 入:hWnd 函数调用窗口句柄
// strRoot 应用程序根目录
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*MM_DestroyObjects)();
// 功 能:释放对象
// 输 入:无
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_GetFontInfo)( char* strFileName, char* strFontName,
int* nInst, void* setInsts,
int* nDrum, void* setDrums );
//功 能:获取音色库信息
//输 入:[IN] strFileName 音色库文件名
// [OUT]strFontName 音色库名称
// [OUT]nInst 乐器音色数(bank=0)
// [OUT]setInsts 乐器音色信息
// [OUT]nDrum 鼓组音色数(bank=128)
// [OUT]setDrums 鼓组音色信息
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_SetDefaultFont)( int num, char strFiles[][256] );
//功 能:设置缺省音色库
//输 入:
// num 文件数
// strFile 音色库文件名数组
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_LoadCompose)( int iFile, LPBYTE lpData, DWORD dwDataSize, int iFont, char* strFontFile );
//功 能:加载编曲数据
//输 入:
// iFile MIDI文件号
// lpData MIDI数据
// dwDataSize 数据大小
// iFont 音源号
// strFontFile 音源文件名
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI void (*MM_FreeComposes)();
//功 能:清空编曲数据
//输 入:
//返回值:无
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*MM_Stop)();
// 功 能:停止播放
// 输 入:
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_Play)( HWND hNotifyWnd, DOUBLE dblStartPoint, int iType );
//功 能:播放
//输 入:hNotifyWnd 接收播放消息的窗口句柄
// dwStartPoint 开始位置
// iChans 播放的通道类型
// TYPE_BASECOMPOSE=0x01, TYPE_COMPOSE=0x02, TYPE_AUDIO=0x04, TYPE_SONG=0x08
// TYPE_BEAT=0x10 TYPE_AUDIO_BASECOMPOSE=0x05, TYPE_SONG_COMPOSE=0x0A
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_LoadDemo)( LPBYTE lpDemoData, DWORD dwDataSize );
//功 能:加载乐器通道试听
//输 入:
// lpDemoData 试听数据
// dwDataSize 数据长度
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_PlayDemo)( HWND hNotifyWnd, double dblBarPlay, int iChno, int iProg,
int iBank, char* strFontFile );
//功 能:播放乐器通道试听
//输 入:hNotifyWnd 接收播放消息的窗口句柄
// dblBarPlay 播放起始小节 -1=循环播放
// iChno 通道号 -1=不改变
// iProg 乐器号 -1=不改变
// iBank 音源号 -1=缺省音源
// strFontFile 音源文件名
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_SetTempo)( int nTempo );
//功 能:设置速度
//输 入:nTempo 速度(拍/分钟)
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_SetTimeSignature)( int nTimeSignature );
//功 能:设置节拍
//输 入:nTimeSignature 节拍(0=4/4, 1=3/4, 2=2/4, 3=6/8
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*MM_SetTrackEvent)( int iEvent, int iStartBar, int iEndBar,
int iChan, int nValue, int iStream );
//功 能:设置通道事件
//输 入:iEvent 事件号
// iFirstBar 起始小节
// iLastBar 结束小节
// iChan 通道号
// nValue 参数值
// iStream 0=完整编曲 -1=Demo
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
extern MM_InitialObjects f_MM_InitialObjects;
extern MM_DestroyObjects f_MM_DestroyObjects;
extern MM_GetFontInfo f_MM_GetFontInfo;
extern MM_SetDefaultFont f_MM_SetDefaultFont;
extern MM_LoadCompose f_MM_LoadCompose;
extern MM_FreeComposes f_MM_FreeComposes;
extern MM_Stop f_MM_Stop;
extern MM_Play f_MM_Play;
extern MM_LoadDemo f_MM_LoadDemo;
extern MM_PlayDemo f_MM_PlayDemo;
extern MM_SetTempo f_MM_SetTempo;
extern MM_SetTimeSignature f_MM_SetTimeSignature;
extern MM_SetTrackEvent f_MM_SetTrackEvent;
/////////////////////////////////////////////////////////////////////////////////////////
string wstr2str(const wstring& _src);
wstring str2wstr(const string& _src);
string UFF8ToMBCS(const char *pcUtf8);
void DebugPrint(const char * fmt, ...);
/////////////////////////////////////////////////////////////////////////////////////////
// ClientService函数段
//
extern TSOFTWAREINFO g_infoSoftwareUpdate;
extern int g_nBuildVersion;
extern TUSERINFO g_infoUser;
extern bool g_bAutoLogin, g_bLogon;
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*CS_UpdateStyle)(UINT idUser, HWND hProcessWnd);
// 功 能:刷新待审核风格信息
// 参 数:idUser 用户ID
// hProcessWnd 进度消息接收窗口
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*CS_CheckStyle)( UINT idTmpStyle, UINT idUser, int score, char* strMsg );
// 功 能:审核风格
// 参 数:
// idTmpStyle 临时风格ID
// idUser 用户ID
// score 评分 0=未通过
// strMsg 未通过的原因
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*CS_UploadStyle)(int iType, UINT idUser, int nDataSize, char* pData,
HWND hProcessWnd);
// 功 能:上传风格文件数据
// 参 数:
// iType 上传类型 1=批量上传 2=制作上传 3=分享上传
// idUser 用户ID
// nDataSize 风格文件数据大小
// pData 风格文件数据
// hProcessWnd 进度消息接收窗口
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT (*CS_InitialService)( HWND hWnd, int iClientType, PTSOFTWAREINFO pSofewareInfo,
char* strURL, char* strRoot, char idDevice[6] );
//功 能:初始化客户端服务
//参 数:hWnd 函数调用窗口句柄
// iClientType 客户端类型(软件内部编号)
// pSofewareInfo[in,out] 传入当前版本,获取更新版本
// strURL 网站服务器名称 http://xxx.xxx.xxx:xx/
// strRoot 资源文件根目录
// idDevice 设备号
//返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*CS_DestroyService)();
// 功 能:解除客户端服务
// 输 入:无
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*CS_Login)(PTUSERINFO pUserInfo, BOOL bSync);
// 功 能:用户登录
// 参 数:pUserInfo[in,out] 传入用户名和密码,输出用户信息
// bSync 同步=TURE,异步=FALSE
// 返回值:错误号
// 正常登录 = 0
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*CS_Logoff)();
// 功 能:注销或取消登录
// 参 数:无
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
typedef DLLAPI HRESULT(*CS_CancelOperation)();
// 功 能:取消操作
// 参 数:
// 返回值:错误号
/////////////////////////////////////////////////////////////////////////////////////////
extern CS_InitialService f_CS_InitialService;
extern CS_DestroyService f_CS_DestroyService;
extern CS_Login f_CS_Login;
extern CS_Logoff f_CS_Logoff;
extern CS_UploadStyle f_CS_UploadStyle;
extern CS_CancelOperation f_CS_CancelOperation;
/*
extern CS_DownloadStyle f_CS_DownloadStyle;
*/
extern CS_UpdateStyle f_CS_UpdateStyle;
extern CS_CheckStyle f_CS_CheckStyle;
/////////////////////////////////////////////////////////////////////////////////////////
HRESULT GetMFFunctions(HINSTANCE hDll);
HRESULT GetMMFunctions(HINSTANCE hDll);
HRESULT GetCSFunctions(HINSTANCE hDll);
HRESULT GetMSFunctions(HINSTANCE hDll);
HRESULT GetSMFunctions(HINSTANCE hDll);
string GBToUTF8(const char* str);
void SetPlayTimer(bool bStart, UINT& tTimer, UINT& tAccuracy,
void* pUser = NULL);
wstring GetElementInfo(int iElem, int iList);
void CALLBACK OnMediaTimer(UINT tTimerID, UINT msg, DWORD dwUser, DWORD dwl,
DWORD dw2);
void SetAutoLogin(bool bAuto, LPCSTR strName, LPCSTR strPwd);
bool GetAutoLogin(char* strName, char* strPwd);
#endif