예제 #1
0
/*
 * Midi clock tick triggered from external clock
 */
void FluidPlayer::musicTick()
{
    // If we use an external device to set the bpm, then we get around
    // Openframeworks updating at a low fps screwing with the clock


    //One crotchet per 24 ticks
    if(clockTick % CROTCHET == 0)
    {
        isBeat = true;
        beatDirty = true;       //Set the beat as dirty so OF updates it when it has time

        //Get the bpm from the last 4 notes
        if( beatCount >= lowerTimesig)
            beatCount = 0;

        if(beatCount == 0) {
            isBar = true;
            firstBeatMs = ofGetElapsedTimeMillis();
            ofLog(OF_LOG_NOTICE, "NEW BAR");
        } else {
            ofLog(OF_LOG_NOTICE, "BEAT");
        }

        if(ofGetElapsedTimeMillis() - firstBeatMs != 0)
            bpm = 60000 * beatCount / (ofGetElapsedTimeMillis() - firstBeatMs);

        if(clockPeriodValue >= upperTimesig-1)
        {
            clockPeriodValue = 0;
            clockTick = 0;
        } else {
            clockPeriodValue++;
        }

        beatCount++;

    } else if(clockTick % DEMISEMIQUAVER == 0) {
        sendNotes();

    } else if(clockTick % baseNoteMessageLength) {
        ofLog(OF_LOG_VERBOSE, "Smallest note");
        isBeat = false;
        isBar = false;
        m_activeInstrument.tickNoteParams();
        sendCC();
    }

    clockPastTime = ofGetElapsedTimeMillis(); //int
    clockTick++; //int
}
예제 #2
0
파일: gameframe.cpp 프로젝트: jpleau/sudoqu
void GameFrame::keyPressEvent(QKeyEvent *event) {
    int key = event->key();

    if (key == Qt::Key_Control && notesEnabled) {
        takingNotes = !takingNotes;
        if (takingNotes) {
            emit toggleTakingNotes("Input mode: NOTE");
        } else {
            emit toggleTakingNotes("Input mode: NORMAL");
        }
        return;
    }

    if (focused == -1 || gameOver) {
        return;
    }

    if (key == Qt::Key_Right || key == Qt::Key_Left || key == Qt::Key_Down || key == Qt::Key_Up) {
        int old_focus = focused;

        int row = focused / 9;
        int col = focused % 9;

        switch (key) {
        case Qt::Key_Right:
            col = moveFocus(1, false);
            break;
        case Qt::Key_Left:
            col = moveFocus(-1, false);
            break;
        case Qt::Key_Up:
            row = moveFocus(-1, true);
            break;
        case Qt::Key_Down:
            row = moveFocus(1, true);
            break;
        }

        focused = row * 9 + col;

        if (focused != old_focus && mode == COOP) {
            emit sendFocusedSquare(focused);
        }

    } else {
        if (key == Qt::Key_0 || key == Qt::Key_Backspace || key == Qt::Key_Delete) {
            if (!takingNotes || !notesEnabled) {
                setAt(focused, 0, true);
            } else {
                notes[focused].clear();
                if (mode == COOP) {
                    emit sendNotes(focused, notes[focused]);
                }
            }
        } else if (key == Qt::Key_Escape) {
            focused = -1;
        } else {
            auto check = key_map.find(key);
            if (check != key_map.end()) {
                if (!takingNotes || !notesEnabled) {
                    setAt(focused, check->second, true);
                } else {
                    if (getAt(focused) > 0) {
                        return;
                    }
                    std::vector<int> &notes_pos = notes[focused];

                    auto iterator = std::find(notes_pos.begin(), notes_pos.end(), check->second);
                    if (iterator == notes_pos.end()) {
                        notes_pos.push_back(check->second);
                        std::sort(notes_pos.begin(), notes_pos.end());
                    } else {
                        notes_pos.erase(iterator);
                    }
                    if (mode == COOP) {
                        emit sendNotes(focused, notes_pos);
                    }
                }
            }
        }
    }
    repaint();
}