Example #1
0
void AudioPlugin::handleTouch(int x, int y) {
    NPP instance = this->inst();

    // if the track is null then return
    if (NULL == m_soundPlay->track) {
        gLogI.log(kError_ANPLogType, "---- %p unable to create track",
                  instance);
        return;
    }

    // check to make sure the currentRect matches the activeRect
    ANPRectF* currentRect = validTouch(x,y);
    if (m_activeTouchRect != currentRect)
        return;

    if (currentRect == &m_playRect) {

        gLogI.log(kDebug_ANPLogType, "---- %p starting track (%d)",
                  m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track));

        if (gSoundI.isStopped(m_soundPlay->track)) {
            gSoundI.start(m_soundPlay->track);
        }
    }
    else if (currentRect == &m_pauseRect) {

        gLogI.log(kDebug_ANPLogType, "---- %p pausing track (%d)",
                  m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track));

        if (!gSoundI.isStopped(m_soundPlay->track)) {
            gSoundI.pause(m_soundPlay->track);
        }
    }
    else if (currentRect == &m_stopRect) {

        gLogI.log(kDebug_ANPLogType, "---- %p stopping track (%d)",
                  m_soundPlay->track, gSoundI.isStopped(m_soundPlay->track));

        if (!gSoundI.isStopped(m_soundPlay->track)) {
            gSoundI.stop(m_soundPlay->track);
        }
        if (m_soundPlay->file) {
            fseek(m_soundPlay->file, 0, SEEK_SET);
        }
    }
    else {
        gLogI.log(kDebug_ANPLogType, "---- touch x:%d, y:%d ", x, y);
        return;
    }

    // set the currentRect to be the activeRect
    m_activeRect = currentRect;
    inval(instance);
}