Tempo Tapper
1.0.0
A simple library to implement a tempo tapper
examples
posix
term_tt_posix_cpp.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2021 Patrick Pedersen
3
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16
*
17
*/
18
47
#include <unistd.h>
48
#include <stdlib.h>
49
#include <stdio.h>
50
#include <curses.h>
51
52
#include <
tempo_tapper_cpp.h
>
// C++ wrapper
53
54
int
main()
55
{
56
tempo_tapper_cpp
tt;
// Create new tempo tapper class object
57
58
if
(!tt.is_init()) {
59
printf(
"term_tt: Failed to create a new tempo tapper object!\n"
);
60
return
EXIT_FAILURE;
// Exit
61
}
62
63
// Initialize ncurses
64
initscr();
65
timeout(-1);
66
curs_set(0);
67
68
char
input;
// Keyboard input
69
70
do
{
71
clear();
72
printw(
"Use the enter key to tap a tempo. Press q to quit.\n"
);
73
refresh();
74
75
while
(1) {
76
input = getchar();
77
clear();
78
79
if
(input ==
'q'
|| input ==
'r'
)
80
break
;
81
else
if
(input ==
'\r'
|| input ==
'\n'
)
82
tt.tap();
// Newline received, tap!
83
else
84
printw(
"Invalid input!\n"
);
85
86
// Get tempo, using tt_bpm(), and tempo period using tt_preiod_us(), and print it out!
87
printw(
"Tempo: %.2f BPM, Period: %.2fms\n"
, tt.bpm(),
float
(tt.period_us())/1000);
88
printw(
"Press r to reset, press q to quit.\n"
);
89
refresh();
90
}
91
92
tt.reset();
// Reset tempo tapper
93
}
while
(input !=
'q'
);
94
95
endwin();
96
return
0;
97
}
tempo_tapper_cpp.h
C++ wrapper for the tempo tapper library.
tempo_tapper_cpp
C++ wrapper for the tempo tapper library.
Definition:
tempo_tapper_cpp.h:45
Generated by
1.8.17