#pragma comment (lib, "LibSynth++.lib")
#include <windows.h>
#include "LibSynth++.h"
bool flag;
HWND hwnd;
wchar_t str[255];
int length;
long pos;
void Init()
{
HDC hdc = GetDC(hwnd);
CControlMessageServer *pControlMessageServer=new
CControlMessageServer();//コントロールメッセージサーバー
CMidiSequencer<24> *pMidiSequencer=new
CMidiSequencer<24>(pControlMessageServer,44100,0.5f);//Midiシーケンサークラス
flag = pMidiSequencer->LoadMidi("test.mid");//Midi読み込み
if(flag){
TextOut(hdc , 10 , 10 , L"Midi読み込み 成功" , 11);
}else{
TextOut(hdc , 10 , 10 , L"Midi読み込み 失敗" , 11);
}
CMixerBuffer<short> MixerBuffer(1000);//ミキサーバッファ
TextOut(hdc , 10 , 35 , L"Midiの長さ:" , 8);
pos = pMidiSequencer->GetLength();//Midiの長さ
_itow(pos,str,10);
length = wcslen(str);
TextOut(hdc , 100 , 35 , str , length);
CWaveOutStream<short> *pWaveOutStream =new
CWaveOutStream<short>(pControlMessageServer, 1000,1);//Wave出力ストリーム
flag = pMidiSequencer->ConnectOutputStream(pWaveOutStream);//接続
if(flag){
TextOut(hdc , 10 , 60 , L"WaveOutStream接続 成功" , 18);
}else{
TextOut(hdc , 10 , 60 , L"WaveOutStream接続 失敗" , 18);
}
flag = pMidiSequencer->GenerateWave(1000);//波形作成
if(flag){
TextOut(hdc , 10 , 85 , L"波形作成 成功" , 7);
}else{
TextOut(hdc , 10 , 85 , L"波形作成 失敗" , 7);
}
TextOut(hdc , 10 , 110 , L"波形の長さ:" , 5);
pos = pMidiSequencer->GetTime();
_itow(pos,str,10);
length = wcslen(str);
TextOut(hdc , 100 , 110 , str , length);
}
//コールバック
LRESULT CALLBACK WndProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp)
{
switch (msg) {
//終了処理
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd , msg , wp , lp);
}
//メイン
int WINAPI WinMain(HINSTANCE hInst , HINSTANCE hPrevI , PSTR lpCmd , int
nCmdShow)
{
MSG msg;
WNDCLASS winc;
winc.style = CS_HREDRAW | CS_VREDRAW;
winc.lpfnWndProc = WndProc;
winc.cbClsExtra = winc.cbWndExtra = 0;
winc.hInstance = hInst;
winc.hIcon = LoadIcon(NULL , IDI_APPLICATION);
winc.hCursor = LoadCursor(NULL , IDC_ARROW);
winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
winc.lpszMenuName = NULL;
winc.lpszClassName = TEXT("window");
if (!RegisterClass(&winc)) return 0;
hwnd = CreateWindow(TEXT("window") , TEXT("Hellow LibSynth++ World!!")
,
WS_OVERLAPPEDWINDOW | WS_VISIBLE ,
100 , 100 , 320 , 240 , NULL , NULL ,hInst , NULL);
if (hwnd == NULL) return 0;
Init();
while (GetMessage(&msg , NULL , 0 , 0)) DispatchMessage(&msg);
return msg.wParam;
}
|