-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_events.cpp
More file actions
92 lines (81 loc) · 3.22 KB
/
Copy pathtest_events.cpp
File metadata and controls
92 lines (81 loc) · 3.22 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
#include <cassert>
#include <cstdio>
#include "encode_helpers.h"
#include "events.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;
auto vocab = build_event_vocab(1001);
auto idx = encode_index_map(1001);
// Simple note start/end via decode_model_tokens
{
std::vector<StreamItem> stream;
stream.push_back(ChunkBoundary{0.f, std::nullopt});
stream.push_back(idx[{"tie", 0}]);
stream.push_back(idx[{"program", 0}]);
stream.push_back(idx[{"velocity", 1}]);
stream.push_back(idx[{"pitch", 60}]);
stream.push_back(idx[{"shift", 50}]);
stream.push_back(idx[{"velocity", 0}]);
stream.push_back(idx[{"pitch", 60}]);
auto events = decode_model_tokens(
stream, vocab, [](int) { return std::string("acoustic_piano"); });
int starts = 0, ends = 0;
for (const auto& e : events) {
if (std::holds_alternative<NoteStartEvent>(e)) ++starts;
if (std::holds_alternative<NoteEndEvent>(e)) ++ends;
}
CHECK(starts == 1);
CHECK(ends == 1);
}
// Drum hit is instantaneous start+end
{
std::vector<StreamItem> stream;
stream.push_back(ChunkBoundary{0.f, std::nullopt});
stream.push_back(idx[{"tie", 0}]);
stream.push_back(idx[{"velocity", 1}]);
stream.push_back(idx[{"drum", 36}]);
auto events = decode_model_tokens(
stream, vocab, [](int) { return std::string("x"); });
CHECK(events.size() == 2);
CHECK(std::holds_alternative<NoteStartEvent>(events[0]));
CHECK(std::holds_alternative<NoteEndEvent>(events[1]));
auto& s = std::get<NoteStartEvent>(events[0]);
CHECK(s.instrument == "drums");
}
// Tie prologue: open note not in tie set closes at boundary
{
OpenNoteTracker tracker(vocab);
// Chunk 0: open a note, leave it open
tracker.feed(ChunkBoundary{0.f, 5.f});
tracker.feed(idx[{"tie", 0}]);
tracker.feed(idx[{"program", 0}]);
tracker.feed(idx[{"velocity", 1}]);
tracker.feed(idx[{"pitch", 60}]);
CHECK(tracker.open_keys().size() == 1);
// Chunk 1: empty tie → closes the open note
auto actions = tracker.feed(ChunkBoundary{5.f, std::nullopt});
CHECK(actions.empty()); // boundary itself doesn't close yet
actions = tracker.feed(idx[{"tie", 0}]);
CHECK(actions.size() == 1);
CHECK(std::holds_alternative<EndNote>(actions[0]));
}
// Progress events pass through
{
std::vector<StreamItem> stream;
stream.push_back(ProgressEvent{0, 2});
stream.push_back(ChunkBoundary{0.f, std::nullopt});
stream.push_back(idx[{"tie", 0}]);
stream.push_back(ProgressEvent{1, 2});
auto events = decode_model_tokens(stream, vocab, [](int) { return std::string("x"); });
CHECK(std::holds_alternative<ProgressEvent>(events[0]));
}
if (g_fails) {
std::fprintf(stderr, "%d failures\n", g_fails);
return 1;
}
std::printf("ok events\n");
return 0;
}