Skip to content
Snippets Groups Projects
Commit 3f9c11ff authored by RANWEZ Pierre's avatar RANWEZ Pierre :anchor:
Browse files

:pencil2: typo: events name simplification

parent 7691e159
Branches
Tags
1 merge request!1✨ feat: CSSLSD V2
...@@ -27,30 +27,23 @@ h1 { ...@@ -27,30 +27,23 @@ h1 {
### MIDI Variables ### MIDI Variables
note:69 | Midi Event | Parameter | Informations |
cc:10 |-------------|-----------|-----------------------------------------|
| note | id | Note on, use case : [note:21] |
| cc | id, range | Control change, use case : [cc:10,0,100]|
- midi
- noteon
- name (ex: C, D, E, F, G, A, B)
- controlchange
- name
### Audio Variables ### Audio Variables
low | Audio Event | Parameter | Informations |
mid |-------------|-----------|-----------------------------------------|
hi | low | range | low energy, use case : [low,0,100] |
loud | lomi | range | lomi energy, use case : [lomi,0,100] |
onset:0.1 | low | range | mid energy, use case : [mid,0,100] |
| mihi | range | mihi energy, use case : [mihi,0,100] |
- audio | hi | range | High energy, use case : [hi,0,100] |
- energy | loud | range | Volume meter, use case : [loud,0,100] |
- bass | onset | note | Note, use case : [onset:A] |
- mid
- treble
- meter
- volume
## Range ## Range
......
let css = "body {\n\tbackground-color:yellow[audio.noteon.E];\n\tbackground-color:white[audio.noteon.A];\n\tbackground-color:blue[audio.noteon.D];\n}\nh1, h2 {\n\tcolor: white[audio.noteon.B];\n\tcolor: red[audio.noteon.A];\n\tfont-size:[audio.meter.volume,0,500]px;\n}"; let css = "body {\n\tbackground-color:yellow[onset:E];\n\tbackground-color:white[onset:A];\n\tbackground-color:blue[onset:D];\n}\nh1, h2 {\n\tcolor: white[onset:B];\n\tcolor: red[onset:A];\n\tfont-size:[loud,0,500]px;\n}";
let activate = false; let activate = false;
let activateFav = "ressources/icon256.png"; let activateFav = "ressources/icon256.png";
let audioB = false; let audioB = false;
......
...@@ -22,14 +22,14 @@ function parseCSS(cssObj) { ...@@ -22,14 +22,14 @@ function parseCSS(cssObj) {
let els = document.querySelectorAll(element.mSelectorText); let els = document.querySelectorAll(element.mSelectorText);
element.declarations.forEach(css => { element.declarations.forEach(css => {
els.forEach(e => { els.forEach(e => {
if (css.valueText.includes('audio')) { if (css.valueText.includes('onset') || css.valueText.includes('onset') || css.valueText.includes('low') || css.valueText.includes('hi')|| css.valueText.includes('loud')) {
audioEvents.push({ audioEvents.push({
'selector': element.mSelectorText, 'selector': element.mSelectorText,
'property': css.property, 'property': css.property,
'value': css.valueText 'value': css.valueText
}) })
} }
if (css.valueText.includes('midi')) { if (css.valueText.includes('note') || css.valueText.includes('cc')) {
midiEvents.push({ midiEvents.push({
'selector': element.mSelectorText, 'selector': element.mSelectorText,
'property': css.property, 'property': css.property,
...@@ -59,8 +59,14 @@ function templateToDict(string) { ...@@ -59,8 +59,14 @@ function templateToDict(string) {
); );
if (string.includes(',')) { if (string.includes(',')) {
eventString = template.split(',')[0]; eventString = template.split(',')[0];
eventType = eventString.split('.')[1]; if (eventString.includes(':')) {
eventName = eventString.split('.')[2]; eventType = eventString.split(':')[0];
eventName = eventString.split(':')[1];
}
else {
eventType = eventString;
eventName = '';
}
min = template.split(',')[1]; min = template.split(',')[1];
max = template.split(',')[2]; max = template.split(',')[2];
returnValue.push({ returnValue.push({
...@@ -71,8 +77,15 @@ function templateToDict(string) { ...@@ -71,8 +77,15 @@ function templateToDict(string) {
'max': max 'max': max
}); });
} }
eventType = string.split('.')[1]; else {
eventName = string.split('.')[2]; if (string.includes(':')) {
eventType = string.split(':')[0];
eventName = string.split(':')[1];
}
else {
eventType = eventString;
eventName = '';
}
returnValue.push({ returnValue.push({
'eventType': eventType, 'eventType': eventType,
'eventName': eventName, 'eventName': eventName,
...@@ -80,6 +93,7 @@ function templateToDict(string) { ...@@ -80,6 +93,7 @@ function templateToDict(string) {
'min': 0, 'min': 0,
'max': 1 'max': 1
}); });
}
string = string.replace('[' + template + ']', ''); string = string.replace('[' + template + ']', '');
} }
return returnValue; return returnValue;
...@@ -142,7 +156,7 @@ function midiEvent(type, data) { ...@@ -142,7 +156,7 @@ function midiEvent(type, data) {
if (result.popup) { if (result.popup) {
switch (type) { switch (type) {
case 'noteon': case 'noteon':
chrome.runtime.sendMessage({ type: 'midiEvent', data: data.note.name }); chrome.runtime.sendMessage({ type: 'midiEvent', data: data.note.number });
break; break;
case 'controlchange': case 'controlchange':
chrome.runtime.sendMessage({ type: 'midiEvent', data: data.controller.name }); chrome.runtime.sendMessage({ type: 'midiEvent', data: data.controller.name });
...@@ -157,14 +171,14 @@ function midiEvent(type, data) { ...@@ -157,14 +171,14 @@ function midiEvent(type, data) {
templates = templateToDict(event['value']); templates = templateToDict(event['value']);
templates.forEach(template => { templates.forEach(template => {
midiValue = (template['min'] + ((template['max'] - template['min']) * midiValue)); midiValue = (template['min'] + ((template['max'] - template['min']) * midiValue));
if (type == 'noteon' && template['eventType'] == 'noteon' && template['eventName'] == data.note.name) { if (type == 'noteon' && template['eventType'] == 'note' && template['eventName'] == data.note.number) {
value = event['value'].replace('[' + template['templateFull'] + ']', midiValue); value = event['value'].replace('[' + template['templateFull'] + ']', midiValue);
let els = document.querySelectorAll(event['selector']); let els = document.querySelectorAll(event['selector']);
els.forEach(e => { els.forEach(e => {
e.style[event['property']] = value; // Note velocity e.style[event['property']] = value; // Note velocity
}); });
} }
if (type == 'controlchange' && template['eventType'] == 'controlchange' && template['eventName'] == data.controller.name) { if (type == 'controlchange' && template['eventType'] == 'cc' && template['eventName'] == data.controller.number) {
value = event['value'].replace('[' + template['templateFull'] + ']', midiValue); value = event['value'].replace('[' + template['templateFull'] + ']', midiValue);
let els = document.querySelectorAll(event['selector']); let els = document.querySelectorAll(event['selector']);
els.forEach(e => { els.forEach(e => {
...@@ -390,16 +404,14 @@ function audioEvent() { ...@@ -390,16 +404,14 @@ function audioEvent() {
var dataArray = new Uint8Array(bufferLength); var dataArray = new Uint8Array(bufferLength);
analyser.getByteFrequencyData(dataArray); analyser.getByteFrequencyData(dataArray);
const presets = { const presets = {
bass: [20, 250], low: [20, 250],
lowMid: [250, 500], lomi: [250, 500],
mid: [500, 2e3], mid: [500, 2e3],
highMid: [2e3, 4e3], mihi: [2e3, 4e3],
treble: [4e3, 16e3] hi: [4e3, 16e3]
} }
var startFreq, endFreq, startBin, endBin, energy; var startFreq, endFreq, startBin, endBin, energy;
energies = []; energies = [];
Object.keys(presets).forEach(key => { Object.keys(presets).forEach(key => {
[startFreq, endFreq] = presets[key]; [startFreq, endFreq] = presets[key];
...@@ -420,7 +432,7 @@ function audioEvent() { ...@@ -420,7 +432,7 @@ function audioEvent() {
} }
audioSample.shift(); audioSample.shift();
audioSample.push(meter.volume); audioSample.push(meter.volume);
console.log(audioEvents);
audioEvents.forEach(event => { audioEvents.forEach(event => {
templates = templateToDict(event['value']); templates = templateToDict(event['value']);
value = event['value']; value = event['value'];
...@@ -431,22 +443,21 @@ function audioEvent() { ...@@ -431,22 +443,21 @@ function audioEvent() {
min = 1; min = 1;
} }
Object.keys(presets).forEach(preset => { Object.keys(presets).forEach(preset => {
if (template['eventType'] == 'energy' && template['eventName'] == preset) { if (template['eventType'] == preset) {
eventIn = true; eventIn = true;
value = value.replace('[' + template['templateFull'] + ']', parseInt(template['min']) + Math.round((template['max'] - template['min']) * energies[preset])); value = value.replace('[' + template['templateFull'] + ']', parseInt(template['min']) + Math.round((template['max'] - template['min']) * energies[preset]));
} }
}); });
if (template['eventType'] == 'meter' && template['eventName'] == 'volume') { if (template['eventType'] == 'loud') {
eventIn = true; eventIn = true;
volume = meter.volume * 1.4; volume = meter.volume * 1.4;
// value = value.replace('[' + template['templateFull'] + ']', (template['max'] * meter.volume));
value = value.replace('[' + template['templateFull'] + ']', (meter.volume * 1.4 < 1 ? parseInt(template['min']) + Math.round((template['max'] - template['min']) * volume) : 0)); value = value.replace('[' + template['templateFull'] + ']', (meter.volume * 1.4 < 1 ? parseInt(template['min']) + Math.round((template['max'] - template['min']) * volume) : 0));
} }
if (event['value'].includes('[audio.noteon.' + noteStrings[note % 12] + ']')) { if (template['eventType'] == 'note' && template['eventName'] == note) {
eventIn = true; eventIn = true;
value = value.replace('[' + template['templateFull'] + ']', ''); value = value.replace('[' + template['templateFull'] + ']', '');
} }
if (attack && template['eventType'] == 'noteon' && template['eventName'] == 'attack') { if (attack && template['eventType'] == 'attack') {
eventIn = true; eventIn = true;
value = value.replace('[' + template['templateFull'] + ']', ''); value = value.replace('[' + template['templateFull'] + ']', '');
} }
...@@ -458,19 +469,6 @@ function audioEvent() { ...@@ -458,19 +469,6 @@ function audioEvent() {
}); });
} }
}); });
// if (meter.checkClipping())
// canvasContext.fillStyle = "red";
// else
// canvasContext.fillStyle = "green";
// canvasContext.fillRect(0, 0, meter.volume * WIDTH * 1.4, HEIGHT);
// set up the next visual callback
// sleepFor(20); // sleepFor(20);
if (audio) { if (audio) {
rafID = window.requestAnimationFrame(audioEvent); rafID = window.requestAnimationFrame(audioEvent);
......
...@@ -15,29 +15,31 @@ function loadEditor() { ...@@ -15,29 +15,31 @@ function loadEditor() {
getCompletions: (editor, session, pos, prefix, callback) => { getCompletions: (editor, session, pos, prefix, callback) => {
// note, won't fire if caret is at a word that does not have these letters // note, won't fire if caret is at a word that does not have these letters
callback(null, [ callback(null, [
{ value: '[audio.meter.volume,0,1]', score: 1, meta: 'Audio meter between 0 and 1.' }, { value: '[loud,0,1]', score: 1, meta: 'Audio meter between 0 and 1.' },
{ value: '[audio.energy.bass,0,1]', score: 1, meta: 'Audio energy bass between 0 and 1.' }, { value: '[low,0,1]', score: 1, meta: 'Audio energy low between 0 and 1.' },
{ value: '[audio.energy.mid,0,1]', score: 1, meta: 'Audio energy mid between 0 and 1.' }, { value: '[lomi,0,1]', score: 1, meta: 'Audio energy low-mid between 0 and 1.' },
{ value: '[audio.energy.treble,0,1]', score: 1, meta: 'Audio energy treble between 0 and 1.' }, { value: '[mid,0,1]', score: 1, meta: 'Audio energy mid between 0 and 1.' },
{ value: '[audio.noteon.C]', score: 1, meta: 'Audio note C' }, { value: '[mihi,0,1]', score: 1, meta: 'Audio energy mid-high between 0 and 1.' },
{ value: '[audio.noteon.C#]', score: 1, meta: 'Audio note C#' }, { value: '[hi,0,1]', score: 1, meta: 'Audio energy treble between 0 and 1.' },
{ value: '[audio.noteon.D]', score: 1, meta: 'Audio note D' }, { value: '[onset:C]', score: 1, meta: 'Audio note C' },
{ value: '[audio.noteon.D#]', score: 1, meta: 'Audio note D#' }, { value: '[onset:C#]', score: 1, meta: 'Audio note C#' },
{ value: '[audio.noteon.E]', score: 1, meta: 'Audio note E' }, { value: '[onset:D]', score: 1, meta: 'Audio note D' },
{ value: '[audio.noteon.F]', score: 1, meta: 'Audio note F' }, { value: '[onset:D#]', score: 1, meta: 'Audio note D#' },
{ value: '[audio.noteon.F#]', score: 1, meta: 'Audio note F#' }, { value: '[onset:E]', score: 1, meta: 'Audio note E' },
{ value: '[audio.noteon.G]', score: 1, meta: 'Audio note G' }, { value: '[onset:F]', score: 1, meta: 'Audio note F' },
{ value: '[audio.noteon.G#]', score: 1, meta: 'Audio note G#' }, { value: '[onset:F#]', score: 1, meta: 'Audio note F#' },
{ value: '[audio.noteon.A]', score: 1, meta: 'Audio note A' }, { value: '[onset:G]', score: 1, meta: 'Audio note G' },
{ value: '[audio.noteon.A#]', score: 1, meta: 'Audio note A#' }, { value: '[onset:G#]', score: 1, meta: 'Audio note G#' },
{ value: '[audio.noteon.B]', score: 1, meta: 'Audio note B' }, { value: '[onset:A]', score: 1, meta: 'Audio note A' },
{ value: '[midi.noteon.C,0,1]', score: 1, meta: 'MIDI Note C between 0 and 1.' }, { value: '[onset:A#]', score: 1, meta: 'Audio note A#' },
{ value: '[midi.noteon.D,0,1]', score: 1, meta: 'MIDI Note D between 0 and 1.' }, { value: '[onset:B]', score: 1, meta: 'Audio note B' },
{ value: '[midi.noteon.E,0,1]', score: 1, meta: 'MIDI Note E between 0 and 1.' }, { value: '[note:24,0,1]', score: 1, meta: 'MIDI Note C between 0 and 1.' },
{ value: '[midi.noteon.F,0,1]', score: 1, meta: 'MIDI Note F between 0 and 1.' }, { value: '[note:26,0,1]', score: 1, meta: 'MIDI Note D between 0 and 1.' },
{ value: '[midi.noteon.G,0,1]', score: 1, meta: 'MIDI Note G between 0 and 1.' }, { value: '[note:28,0,1]', score: 1, meta: 'MIDI Note E between 0 and 1.' },
{ value: '[midi.noteon.A,0,1]', score: 1, meta: 'MIDI Note A between 0 and 1.' }, { value: '[note:29,0,1]', score: 1, meta: 'MIDI Note F between 0 and 1.' },
{ value: '[midi.noteon.B,0,1]', score: 1, meta: 'MIDI Note B between 0 and 1.' }, { value: '[note:31,0,1]', score: 1, meta: 'MIDI Note G between 0 and 1.' },
{ value: '[note:33,0,1]', score: 1, meta: 'MIDI Note A between 0 and 1.' },
{ value: '[note:35,0,1]', score: 1, meta: 'MIDI Note B between 0 and 1.' },
]); ]);
}, },
}], }],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment