-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.cpp
More file actions
55 lines (47 loc) · 1.29 KB
/
Copy pathUtilities.cpp
File metadata and controls
55 lines (47 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Arduino.h>
#include "Utilities.h"
#include "Sharp.h"
#include "noteset.h"
static char *notestr = NULL;
const char *notes[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
// A0 = 33 is the lowest I will support
// C8 = 120 is the highest I will support
char *getnotestring(byte midipitch, bool inclNumber)
{
if (!notestr)
notestr = (char *)calloc(12, sizeof(char));
int octave = floor(midipitch / 12) - 1;
const char *ns = (midipitch < 33 || midipitch > 120) ? "-" : notes[midipitch % 12];
if (inclNumber)
sprintf(notestr, "%s%d[%d]", ns, octave, midipitch);
else
sprintf(notestr, "%s%d", ns, octave);
return notestr;
}
// share the string
static char *diagstr = NULL;
char *getnotesetstring(const char *name, noteset *set)
{
int i, n;
if (diagstr)
diagstr[0] = 0;
else
diagstr = (char *)calloc(300, sizeof(char));
char *pstr = diagstr;
n = sprintf(pstr, "%s %d [%d]: ", name, set->count, set->heldcount);
pstr += n;
for (i = 0; i < set->count; ++i)
{
char *notestr = getnotestring(set->notes[i].pitch, true);
n = sprintf(pstr, "%s ", notestr);
pstr += n;
if (set->notes[i].latched)
{
if ((pstr - 1)[0] == ' ')
pstr--;
sprintf(pstr, "* ");
pstr += 2;
}
}
return diagstr;
}