-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_notes.cpp
More file actions
97 lines (86 loc) · 3.07 KB
/
Copy pathtest_notes.cpp
File metadata and controls
97 lines (86 loc) · 3.07 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <cassert>
#include <cstdio>
#include <cmath>
#include "encode_helpers.h"
#include "vocab.h"
static int g_fails = 0;
#define CHECK(cond) do { if (!(cond)) { std::fprintf(stderr, "FAIL %s:%d %s\n", __FILE__, __LINE__, #cond); ++g_fails; } } while(0)
int main() {
using namespace muscriptor;
// sort notes
{
std::vector<Note> notes = {
{false, 0, 2.f, 3.f, 60},
{false, 0, 0.5f, 1.5f, 62},
{false, 0, 1.f, 2.f, 64},
};
sort_notes(notes);
CHECK(notes[0].onset <= notes[1].onset && notes[1].onset <= notes[2].onset);
}
// validate short duration
{
Note note{false, 0, 1.f, 1.001f, 60};
auto result = validate_notes({note}, MINIMUM_NOTE_DURATION_SEC, true);
CHECK(result[0].offset >= result[0].onset + MINIMUM_NOTE_DURATION_SEC);
}
// validate inverted
{
Note note{false, 0, 2.f, 1.f, 60};
auto result = validate_notes({note}, MINIMUM_NOTE_DURATION_SEC, true);
CHECK(result[0].offset >= result[0].onset);
}
// trim overlap
{
std::vector<Note> notes = {
{false, 0, 0.f, 2.f, 60},
{false, 0, 1.f, 3.f, 60},
};
auto result = trim_overlapping_notes(notes);
CHECK(result[0].offset == result[1].onset);
}
// vocab layout
{
auto vocab = build_event_vocab(1001);
CHECK(vocab.size() == 1393);
CHECK(vocab[0].type == "PAD");
CHECK(vocab[1].type == "EOS");
CHECK(vocab[2].type == "UNK");
CHECK(vocab[3].type == "shift" && vocab[3].value == 0);
CHECK(vocab[1003].type == "shift" && vocab[1003].value == 1000);
CHECK(vocab[1004].type == "pitch" && vocab[1004].value == 0);
CHECK(vocab[1131].type == "pitch" && vocab[1131].value == 127);
CHECK(vocab[1132].type == "velocity" && vocab[1132].value == 0);
CHECK(vocab[1133].type == "velocity" && vocab[1133].value == 1);
CHECK(vocab[1134].type == "tie");
CHECK(vocab[1135].type == "program" && vocab[1135].value == 0);
CHECK(vocab[1264].type == "program" && vocab[1264].value == 129);
CHECK(vocab[1265].type == "drum" && vocab[1265].value == 0);
CHECK(vocab[1392].type == "drum" && vocab[1392].value == 127);
}
// encode/decode roundtrip
{
std::vector<NoteEvent> nes = {
{false, 0, 0.1f, 1, 60},
{false, 0, 0.5f, 0, 60},
{true, DRUM_PROGRAM, 0.2f, 1, 36},
};
auto tokens = encode_note_events(nes, 1001);
auto vocab = build_event_vocab(1001);
auto decoded = decode_tokens(tokens, vocab);
CHECK(decoded.note_events.size() >= 2);
}
// note2note_event roundtrip-ish
{
std::vector<Note> notes = {{false, 0, 0.f, 1.f, 60}};
auto nes = note2note_event(notes);
CHECK(nes.size() == 2);
CHECK(nes[0].velocity == 1);
CHECK(nes[1].velocity == 0);
}
if (g_fails) {
std::fprintf(stderr, "%d failures\n", g_fails);
return 1;
}
std::printf("ok notes\n");
return 0;
}