-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOSCBPM.js
142 lines (125 loc) · 3.35 KB
/
OSCBPM.js
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
a: zak45
d: 07/04/2023
v: 2.0.0
Script to detect each Beat from aubio via osc
From odd to even.
Provide list of probable genres.
To be used with WLEDAudioSync module.
*/
var newOSCRTContainer = '';
var soundCardModule = root.modules.soundCard;
var beat = '';
var beat_SC = '';
var beat_Exist = false;
var prob = '';
var bpm_Value = 0;
function init()
{
local.register("/WLEDAudioSync/beat/BPM", "OSCBPM");
newOSCRTContainer = local.addContainer("WLEDAudioSync");
beat = newOSCRTContainer.addBoolParameter("Beat", "Beat odd even", true);
if (soundCardModule.name != "undefined")
{
beat_SC = soundCardModule.values.addBoolParameter("Beat", "Beat odd even", true);
beat_SC.setAttribute("readOnly", true);
bpm_SC = soundCardModule.values.addFloatParameter("BPM", "Beat Per Minute", 0);
bpm_SC.setAttribute("readOnly", true);
beat_Exist = true;
}
prob = newOSCRTContainer.addStringParameter("ProbGenre", "List of Probable playing music genres based on the BPM", '[]');
}
function OSCBPM(address, args)
{
//script.log("Received message : "+ address + " with value of : " + args[0]);
bpm_Value = parseInt(local.values._WLEDAudioSync_beat_BPM.get());
if (beat.get() == 0)
{
beat.set(1);
if (beat_Exist)
{
beat_SC.set(1);
bpm_SC.set(bpm_Value);
root.modules.wLEDAudioSync.values.beat.set(1);
}
} else {
beat.set(0);
if (beat_Exist)
{
beat_SC.set(0);
root.modules.wLEDAudioSync.values.beat.set(0);
}
}
prob.set(getProbableGenres(bpm_Value));
}
// We take the BPM to obtain a list of genre probability, based on medium values.
// could be associated to RTMGC
function getProbableGenres (bpm)
{
// Name: min BPM, max BPM
var genres = [
'Ambient: 60, 100',
'Bachata: 128, 128',
'Ballad: 60, 80',
'Blues: 60, 120',
'Blues Rock: 100, 120',
'Classical: 60, 120',
'Country: 60, 120',
'Crunk: 80, 80',
'Cumbia: 70, 80',
'Disco: 110, 140',
'Deep House: 120, 125',
'Down Tempo: 70, 100',
'Drum n Bass: 160, 180',
'Dubstep: 130, 150',
'Electro House: 125, 130',
'Electronic: 120, 140',
'Eurodance: 126, 132',
'Euro House: 126, 130',
'Frenchcore: 200, 210',
'Folk: 90, 130',
'Funk: 90, 120',
'Funk Metal: 115, 130',
'Funky House: 128, 136',
'Hard Rock: 122, 160',
'Heavy Metal: 100, 135',
'Hip Hop: 85, 115',
'House: 120, 130',
'Indie: 100, 160',
'Jazz: 80, 140',
'Latin: 90, 130',
'Louisiana Blues: 80, 120',
'Makina: 150, 190',
'Metal: 100, 200',
'New Beat: 110, 120',
'Pop: 90, 130',
'Psytrance: 140, 145',
'Punk: 150, 200',
'R&B: 60, 100',
'Rap: 90, 100',
'Reggae: 60, 110',
'Reggaeton: 80, 90',
'Rock: 100, 160',
'Salsa: 150, 250',
'Soul: 60, 120',
'Synth-pop: 90, 130',
'Tango: 50, 56',
'Tech House: 120, 135',
'Techno: 120, 140',
'Techno Hardcore: 170, 200',
'Trap: 139, 141',
'Trance: 130, 150',
'Tribe: 145, 180',
'Trip Hop: 60, 120',
'UK Garage: 130, 135'
];
var probableGenres = "";
for (var i = 0; i < genres.length; i ++) {
var genre = genres[i].split(':');
var bpmRange = genre[1].split(',');
if (bpm >= parseInt(bpmRange[0]) && bpm <= parseInt(bpmRange[1])) {
probableGenres = probableGenres + genre[0] + ",";
}
}
return probableGenres.substring(0,probableGenres.length-1);
}