Auto full-combo Koibumi2000 in Taiko no Tatsujin CS5

Dependencies:   fll mbed-rtos mbed

taiko.cpp

Committer:
amutake
Date:
2015-02-15
Revision:
11:21b3b0494baa
Parent:
10:79bb44beb08b
Child:
12:54aeb978fe9d

File content as of revision 11:21b3b0494baa:

// Toolkit for Taiko no Tatsujin

#include "fll.h"
#include "taiko.h"

Serial pc(USBTX, USBRX);

button_t taiko2button(Taiko t)
{
    switch (t) {
        case Don:
            return CIRCLE;
        case Ka:
            return R1;
        case Un:
            return 0;
    }
    return 0;
}

TaikoSource::TaikoSource(note** ns, int s, float b)
{
    note_seq = ns;
    size = s;
    bpm = b;
    index = 0;
    frame_i = 0;
    lag = 0;
}

button_t TaikoSource::await()
{
    if (index >= size) {
        return 0;
    }

    note* n = note_seq[index];
    float len = n->length * (60 / bpm); // note length (sec)
    float passing = frame_i * FRAME; // passing time since the begining of this note (sec)

    frame_i++;

    button_t btn = 0;
    if (passing < len / 2) { // in the former of this note
        btn = taiko2button(n->taiko);
    } else if (passing + FRAME >= len - lag) { // final frame of this note
        frame_i = 0;
        index++;
        lag = passing + FRAME - (len - lag);
    }
    return btn;
}