Пример #1
0
int main(int argc, char* argv[])
{
    // header
    cout << "\n  Modus " << MODUS_VERSION;
    cout << "\n  C++ Music Library";
    cout << "\n  Sample Application\n\n";

    // instrument
    MSRange mDoubleBassRange(28, 60);
    MCInstrument mDoubleBass(1, mDoubleBassRange, 1);

    // sound generator
    CAudio::init();
    MCSoundGenAudio* mSoundGen = CAudio::createSoundGen(1, mDoubleBass.getNumberOfChannels(), false);
    sprintf(sFilename, InstrumentsPath, "DoubleBass.msp");
    mSoundGen->loadSamplePack(sFilename);

    // double bass settings
    mDoubleBass.setSoundGen(mSoundGen);

    // timer
    MCTimer mTimer;
    mTimer.setCallbackTick(TimerTick, &mDoubleBass);
    mTimer.start();

    // create music timer thread
#ifdef _WIN32
    HANDLE hMusicTimerThread = CreateThread(NULL, 0, MusicTimerThread, &mTimer, 0, NULL);
#else
    pthread_t hMusicTimerThread;
    pthread_create(&hMusicTimerThread, NULL, MusicTimerThread, &mTimer);
#endif

    // bending parameters
    MSNote mNote;
    int iBendingCents;
    unsigned int iBendingTicks;

    while(1)
    {
        do
        {
            cout << "  Bending cents [-1200, 1200]. Enter 0 to quit: ";
            cin >> iBendingCents;

        } while(iBendingCents < -1200 || iBendingCents > 1200);

        // quit
        if(iBendingCents == 0)
            break;

        do
        {
            cout << "  Bending duration in ticks [1, 96]: ";
            cin >> iBendingTicks;

        } while(iBendingTicks < 1 || iBendingTicks > 96);

        cout << "  Playing note and bending...\n\n";

        mNote.Pitch = 40;
        mNote.Intensity = 127;

        mDoubleBass.playNote(mNote);
        mDoubleBass.bend(0, iBendingCents, iBendingTicks);
    }

    // wait until the music timer thread finishes
    bThreadEnd = true;

#ifdef _WIN32
    WaitForSingleObject(hMusicTimerThread, INFINITE);
    CloseHandle(hMusicTimerThread);
#else
    pthread_join(hMusicTimerThread, NULL);
#endif

    delete mSoundGen;

    CAudio::release();

    cout << "\n\n";

    return 0;
}
Пример #2
0
int main(int argc, char* argv[])
{
    // header
    cout << "\n  Modus " << MODUS_VERSION;
    cout << "\n  C++ Music Library";
    cout << "\n  Sample Application\n\n";

    // global data
    SGlobal sGlobal;

    // instrument
    MSRange mTrumpetRange(52, 84);
    sGlobal.mTrumpet = new MCInstrument(1, mTrumpetRange, 1);

    // sound generator
    CAudio::init();
    MCSoundGenAudio* mSoundGen = CAudio::createSoundGen(1, sGlobal.mTrumpet->getNumberOfChannels(), false);
    sprintf(sFilename, InstrumentsPath, "Trumpet.msp");
    mSoundGen->loadSamplePack(sFilename);

    // score
    sprintf(sFilename, ScriptsPath, "score.trumpet.sample.txt");
    sGlobal.mScore.loadScriptFromFile(sFilename);

    // instrument settings
    sGlobal.mTrumpet->setScore(&sGlobal.mScore);
    sGlobal.mTrumpet->setSoundGen(mSoundGen);

    // timer
    MCTimer mTimer(132, 4);
    mTimer.setCallbackTick(TimerTick, &sGlobal);
    mTimer.start();

    // create music timer thread
#ifdef _WIN32
    HANDLE hMusicTimerThread = CreateThread(NULL, 0, MusicTimerThread, &mTimer, 0, NULL);
#else
    pthread_t hMusicTimerThread;
    pthread_create(&hMusicTimerThread, NULL, MusicTimerThread, &mTimer);
#endif

    cout << "\n  Playing! Options:\n";
    cout << "\n    M -> change mode";
    cout << "\n    ESC -> quit\n\n";

    int iKey = 0;
    bool bMode = false;
    unsigned int i;

    Input::init();

    while(iKey != 27)
    {
        iKey = toupper(Input::getKey());

        if(iKey == 'M')
        {
            for(i = 0; i < sGlobal.mScore.getNumberOfEntries(); i++)
                sGlobal.mScore[i]->Note.Mode = (bMode)? 1: 0;

            bMode = !bMode;
        }

        wait(1);
    }

    Input::close();

    // wait until the music timer thread finishes
    bThreadEnd = true;

#ifdef _WIN32
    WaitForSingleObject(hMusicTimerThread, INFINITE);
    CloseHandle(hMusicTimerThread);
#else
    pthread_join(hMusicTimerThread, NULL);
#endif

    delete sGlobal.mTrumpet;
    delete mSoundGen;

    CAudio::release();

    cout << "\n\n";

    return 0;
}
Пример #3
0
int main(int argc, char* argv[])
{
    // header
    cout << "\n  Modus " << MODUS_VERSION;
    cout << "\n  C++ Music Library";
    cout << "\n  Sample Application\n";

    // global data
    SGlobal sGlobal;

    // instrument
    MSRange mDrumsRange(35, 59);
    sGlobal.mDrums = new MCInstrument(1, mDrumsRange, 16);

    // score
    sprintf(sFilename, ScriptsPath, "score.drums.sample.txt");
    sGlobal.mScore.loadScriptFromFile(sFilename);

    // sound generator
    CAudio::init();
    MCSoundGenAudio* mSoundGen = new MCSoundGenFMOD(sGlobal.mDrums->getNumberOfChannels(), false, 
                                                    CAudio::getSoundSystem());
    sprintf(sFilename, InstrumentsPath, "Drums.msp");
    mSoundGen->loadSamplePack(sFilename);

    // drums settings
    sGlobal.mDrums->setScore(&sGlobal.mScore);
    sGlobal.mDrums->setSoundGen(mSoundGen);

    // song structure object
    MSSongSection mFirstSection;
    mFirstSection.FirstMeasure = 1;
    mFirstSection.LastMeasure = LOOP;
    mFirstSection.Tempo = TEMPO_A;
    mFirstSection.TargetTempo = TEMPO_B;
    mFirstSection.BeatsPerMeasure = 4;

    sGlobal.mStructure.addEntry(mFirstSection);

    // timer
    sGlobal.mTimer.setSongStructure(&sGlobal.mStructure);
    sGlobal.mTimer.setCallbackTick(TimerTick, &sGlobal);
    sGlobal.mTimer.start();

    cout << "\n  Playing! Press any key to quit\n";
    cout << "\n  Accelerando...";
    fflush(stdout);

    Input::init();

    while(!Input::keyPressed())
    {
        if(sGlobal.mTimer.update())
            CAudio::update();
    }

    Input::close();

    delete sGlobal.mDrums;
    delete mSoundGen;

    CAudio::release();

    cout << "\n\n";

    return 0;
}
Пример #4
0
int main(int argc, char* argv[])
{
    // instrument
    MSRange mPianoRange(21, 108);
    MCInstrument mPiano(1, mPianoRange, mPianoRange.getSize());

    // header
    cout << "\n  Modus " << MODUS_VERSION;
    cout << "\n  C++ Music Library";
    cout << "\n  Sample Application";

    // list of MIDI in devices
    std::string sDevice;
    unsigned int iNumDevices;
    unsigned int iSelectedDevice;

    RtMidiIn mDevice(rtMidiApi, "Modus Sample");
    iNumDevices = mDevice.getPortCount();

    if(iNumDevices == 0)
    {
        cout << "\n\n  ERROR: no MIDI in devices found\n\n";
        cin.get();

        return 0;
    }
    
    cout << "\n\n  Select a MIDI in device:\n";

    for(unsigned int i = 0; i < iNumDevices; i++)
    {
        sDevice = mDevice.getPortName(i);
        cout << "\n  " << i + 1 << ") " << sDevice;
    }

    cout << "\n\n";

    do
    {
        cout << "  -> ";
        cin >> iSelectedDevice;

    } while(iSelectedDevice < 1 || iSelectedDevice > iNumDevices);

    iSelectedDevice--;

    // MIDI listener
    mDevice.openPort(iSelectedDevice);
    mDevice.setCallback(&MidiInProc);
    
    // Modus MIDI receiver
    mMIDIReceiver = new MCMIDIReceiver(&mPiano);
    mMIDIReceiver->listenToAllMIDIChannels();
    mMIDIReceiver->attachAllPitchesToDifferentChannels();

    // sound generator
    CAudio::init();
    MCOpenALSourceManager mALManager(OPENAL_SOURCES);
    MCSoundGenAudio* mSoundGen = new MCSoundGenOpenAL(mPiano.getNumberOfChannels(), false, 1, &mALManager);
    sprintf(sFilename, InstrumentsPath, "Piano.msp");
    mSoundGen->loadSamplePack(sFilename);
    mPiano.setSoundGen(mSoundGen);

    // timer
    MCTimer mTimer;
    mTimer.setCallbackTick(TimerTick, &mPiano);
    mTimer.start();

    cout << "\n  Listening, you can play now! Press any key to quit...";
    fflush(stdout);

    Input::init();

    while(!Input::keyPressed())
        mTimer.update();

    Input::close();

    delete mMIDIReceiver;
    delete mSoundGen;
    CAudio::release();

    cout << "\n\n";

    return 0;
}
Пример #5
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR sCmdLine, int iCmdShow)
{
    static char sAppName[] = "Modus Sample";
    HWND hWnd;
    MSG iMsg;
    WNDCLASSEX wndClass;

    // window size
    sGDI.WindowSizeX = 924;
    sGDI.WindowSizeY = 280;

    // class properties
    wndClass.cbSize = sizeof(wndClass);
    wndClass.style = CS_HREDRAW | CS_VREDRAW;
    wndClass.lpfnWndProc = WndProc;
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hInstance = hInstance;
    wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndClass.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
    wndClass.lpszMenuName = NULL;
    wndClass.lpszClassName = sAppName;
    wndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    // register the class
    RegisterClassEx(&wndClass);

    // create main window
    hWnd = CreateWindow(sAppName, "Modus - C++ Music Library",
                        WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
                        CW_USEDEFAULT, CW_USEDEFAULT, sGDI.WindowSizeX, sGDI.WindowSizeY,
                        NULL, NULL, hInstance, NULL);

    // store window's handle
    sGDI.hWnd = hWnd;

    // initialize global data
    SGlobal sGlobal;

    sGlobal.mPiano = NULL;
    memset(sGlobal.bKeyPressed, 0, 88);
    memset(sGlobal.iKeyIntensity, 0, 88);
    sGlobal.bDamper = false;

    // make global data accesible to WndProc()
    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG)&sGlobal);

    // instrument
    MSRange mPianoRange(21, 108);
    sGlobal.mPiano = new MCInstrument(1, mPianoRange, mPianoRange.getSize());

    // scores
    sGlobal.mScores = new MCScore[SCORES];

    sGlobal.mScores[0].loadScriptFromFile(".\\..\\..\\common\\scripts\\score.piano.chopin.txt");
    sGlobal.mScores[1].loadScriptFromFile(".\\..\\..\\common\\scripts\\score.piano.chopin2.txt");
    sGlobal.mScores[1].displace(1);

    sGlobal.iCurrentScore = 0;

    // sound generator
    CAudio::init();
    MCSoundGenAudio* mSoundGen = CAudio::createSoundGen(1, sGlobal.mPiano->getNumberOfChannels(), false);
    mSoundGen->loadSamplePack(".\\..\\..\\common\\instruments\\Piano.msp");

    // instrument settings
    sGlobal.mPiano->setScore(&sGlobal.mScores[sGlobal.iCurrentScore]);
    sGlobal.mPiano->setSoundGen(mSoundGen);

    sGlobal.mPiano->setCallbackPlay(PianoPlayNote, &sGlobal);
    sGlobal.mPiano->setCallbackRelease(PianoReleaseNote, &sGlobal);
    sGlobal.mPiano->setCallbackDamper(PianoDamper, &sGlobal);

    // initalize critical section
    InitializeCriticalSection(&sGlobal.cSection);

    // music timer
    sGlobal.mMusicTimer = new MCTimer(TEMPO, 4);
    sGlobal.mMusicTimer->setCallbackTick(TimerTick, &sGlobal);
    sGlobal.mMusicTimer->start();

    // create music timer thread
    HANDLE hMusicTimerThread = CreateThread(NULL, 0, MusicTimerThread, &sGlobal, 0, NULL);

    // loop timer
    Timer* mLoopTimer = new Timer();
    mLoopTimer->start();

    double dTimeInterval = 1000000.0 / FPS;
    double dTimeDelta = 0;
    double dTimeBefore = 0;
    double dTimeNow;

    // initialize rendering system
    CRendering::init(&sGDI);

    // show window
    ShowWindow(hWnd, iCmdShow);

    // main loop
    while(!bEnd)
    {
        // input
        if(PeekMessage(&iMsg, NULL, 0, 0, PM_REMOVE)) 
        {
            TranslateMessage(&iMsg);
            DispatchMessage(&iMsg);
        }
        
        // render
        dTimeNow = mLoopTimer->getTime();
        dTimeDelta = dTimeNow - dTimeBefore;

        if(dTimeDelta >= dTimeInterval)
        {
            dTimeBefore = dTimeNow;
            RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE);
        }
    }

    // wait until the music timer thread finishes
    WaitForSingleObject(hMusicTimerThread, INFINITE);
    CloseHandle(hMusicTimerThread);

    DeleteCriticalSection(&sGlobal.cSection);

    delete sGlobal.mPiano;
    delete[] sGlobal.mScores;
    delete mSoundGen;
    delete sGlobal.mMusicTimer;
    delete mLoopTimer;

    CRendering::release();
    CAudio::release();

    return 0;
}