Beispiel #1
0
static void processEvent(SDL_Event* e, InputContext* inputState, PlatformState* state) {
    ControllerInput* keyboardController = getContoller(inputState, 0);
    switch (e->type) {
        case SDL_QUIT:
            state->running = false;
            break;
        case SDL_WINDOWEVENT:
            processWindowEvent(&e->window);
            break;

        case SDL_KEYDOWN:
        case SDL_KEYUP:
            bool isDown = e->key.state == SDL_PRESSED;
            isDown &= e->key.state != SDL_RELEASED;
            if(e->key.repeat == 0) {
                switch(e->key.keysym.sym) {
                    case SDLK_w:
                        processKeyPress(&keyboardController->directionUp, isDown);
                        break;
                    case SDLK_s:
                        processKeyPress(&keyboardController->directionDown, isDown);
                        break;
                    case SDLK_a:
                        processKeyPress(&keyboardController->directionLeft, isDown);
                        break;
                    case SDLK_d:
                        processKeyPress(&keyboardController->directionRight, isDown);
                        break;
                    case SDLK_l: //start/stop recording
                        if(isDown && !state->isPlayingBack) {
                            if(state->isRecording) {
                                stopRecording(state);
                            }
                            else {
                                beginRecording(state);
                            }
                        }
                        break;
                    case SDLK_p: //start/stop playback
                        if(isDown && !state->isRecording) {
                            if(state->isPlayingBack) {
                                stopPlayback(state);
                                *inputState = {};
                            }
                            else {
                                beginPlayback(state);
                            }
                        }
                        break;
                }
            }
            break;
    }

}
void SuperColliderLoopElement::setBeat(int beat) {
    this->beat = beat;
    if (beat % getNumBeats() == 0 && getPlaying())
    {
        count = (count + 1) % getSkip();
        if (count % (numBeats * getSkip()) == 0) {
            if (!mute) play();
            count = 0;
        }
    }
    
    if (beat == 0 && getToRecord()) {
        beginRecording();
    }
    else if (isRecord && (beat >= numBeats || beat == 0)) {
        setRecording(false);
    }
}