Example #1
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;
}
Example #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";

    // 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;
}
Example #3
0
int main(int argc, char* argv[])
{
    // instrument
    MSRange mPianoRange(21, 108);
    MCInstrument mPiano(1, mPianoRange, mPianoRange.getSize());

    // score
    MCScore mScore;
    sprintf(sFilename, ScriptsPath, "score.piano.chopin.txt");
    mScore.loadScriptFromFile(sFilename);

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

    // list of MIDI out devices
    unsigned int iNumDevices;
    unsigned int iSelectedDevice;
    unsigned int i;

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

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

        return 0;
    }

    cout << "\n\n  Select a MIDI out device:\n";

    for(i = 0; i < iNumDevices; i++)
        cout << "\n  " << i + 1 << ") " << mDevice.getPortName(i);

    cout << "\n\n";

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

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

    iSelectedDevice--;

    // sound generator
    mDevice.openPort(iSelectedDevice);
    MCSoundGen* mSoundGen = new MCSoundGenMIDI(mPiano.getNumberOfChannels(), &mDevice, 1, 1);

    // piano settings
    mPiano.setScore(&mScore);
    mPiano.setSoundGen(mSoundGen);

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

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

    Input::init();

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

    Input::close();

    delete mSoundGen;

    mDevice.closePort();

    cout << "\n\n";

    return 0;
}