Download code/test/C++/0025230_Tempo.cpp from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 786 Bytes
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/test/C%2B%2B/0025230_Tempo.cpp
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/test/C++/0025230_Tempo.cpp
-
curl -L -o 0025230_Tempo.cpp https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/test/C%2B%2B/0025230_Tempo.cpp
786 Bytes
| Tempo::Tempo(){ | |
| tapIdx = 0; | |
| isDoubleTap = false; | |
| tempo = 500; | |
| } | |
| void Tempo::init(){ | |
| for(uint8_t idx = 0; idx < TAP_COUNT; idx++){ | |
| tapTimes[idx] = 0; | |
| } | |
| } | |
| void Tempo::tap(){ | |
| uint8_t idx = tapIdx % TAP_COUNT; | |
| tapTimes[idx] = millis(); | |
| this -> runCalc(); | |
| tapIdx++; | |
| } | |
| void Tempo::runCalc(){ | |
| uint8_t beats = 0; | |
| uint16_t durration = 0; | |
| isDoubleTap = false; | |
| for(uint8_t idx = 1; idx < TAP_COUNT; idx++){ | |
| int16_t diff = tapTimes[idx] - tapTimes[idx - 1]; | |
| if(diff > DOUBLE_TAP_PERIOD && diff < MAXIMUM_PERIOD){ | |
| beats++; | |
| durration += diff; | |
| }else if(diff > 0 && diff < DOUBLE_TAP_PERIOD){ | |
| isDoubleTap = true; | |
| tapTimes[idx] = tapTimes[idx-1]; | |
| } | |
| } | |
| if(beats > 0){ | |
| tempo = durration/beats; | |
| } | |
| } | |