From 3f9c11ff320d71cad19bd065e1e088aef6c821c9 Mon Sep 17 00:00:00 2001 From: Pierre Ranwez <pierre.ranwez.etu@univ-lille.fr> Date: Tue, 1 Feb 2022 15:00:37 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20typo:=20events=20name=20si?= =?UTF-8?q?mplification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 33 ++++++++------------ background.js | 12 +++---- content.js | 86 +++++++++++++++++++++++++-------------------------- main.js | 48 ++++++++++++++-------------- 4 files changed, 86 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 22ff3b7..cb20959 100644 --- a/README.md +++ b/README.md @@ -27,30 +27,23 @@ h1 { ### MIDI Variables -note:69 -cc:10 +| Midi Event | Parameter | Informations | +|-------------|-----------|-----------------------------------------| +| 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 -low -mid -hi -loud -onset:0.1 - -- audio - - energy - - bass - - mid - - treble - - meter - - volume +| Audio Event | Parameter | Informations | +|-------------|-----------|-----------------------------------------| +| low | range | low energy, use case : [low,0,100] | +| lomi | range | lomi energy, use case : [lomi,0,100] | +| low | range | mid energy, use case : [mid,0,100] | +| mihi | range | mihi energy, use case : [mihi,0,100] | +| hi | range | High energy, use case : [hi,0,100] | +| loud | range | Volume meter, use case : [loud,0,100] | +| onset | note | Note, use case : [onset:A] | ## Range diff --git a/background.js b/background.js index 15a19e2..55a22f7 100644 --- a/background.js +++ b/background.js @@ -1,4 +1,4 @@ -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 activateFav = "ressources/icon256.png"; let audioB = false; @@ -22,10 +22,10 @@ chrome.runtime.onInstalled.addListener(() => { /** * @description This function is called when popup is opened and add a listener when user close it. */ -chrome.runtime.onConnect.addListener(function(port) { - if (port.name === "popup") { - port.onDisconnect.addListener(function() { +chrome.runtime.onConnect.addListener(function (port) { + if (port.name === "popup") { + port.onDisconnect.addListener(function () { chrome.storage.sync.set({ popup: false }); - }); - } + }); + } }); \ No newline at end of file diff --git a/content.js b/content.js index 82cae17..bec3d58 100644 --- a/content.js +++ b/content.js @@ -22,14 +22,14 @@ function parseCSS(cssObj) { let els = document.querySelectorAll(element.mSelectorText); element.declarations.forEach(css => { 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({ 'selector': element.mSelectorText, 'property': css.property, 'value': css.valueText }) } - if (css.valueText.includes('midi')) { + if (css.valueText.includes('note') || css.valueText.includes('cc')) { midiEvents.push({ 'selector': element.mSelectorText, 'property': css.property, @@ -59,8 +59,14 @@ function templateToDict(string) { ); if (string.includes(',')) { eventString = template.split(',')[0]; - eventType = eventString.split('.')[1]; - eventName = eventString.split('.')[2]; + if (eventString.includes(':')) { + eventType = eventString.split(':')[0]; + eventName = eventString.split(':')[1]; + } + else { + eventType = eventString; + eventName = ''; + } min = template.split(',')[1]; max = template.split(',')[2]; returnValue.push({ @@ -71,15 +77,23 @@ function templateToDict(string) { 'max': max }); } - eventType = string.split('.')[1]; - eventName = string.split('.')[2]; - returnValue.push({ - 'eventType': eventType, - 'eventName': eventName, - 'templateFull': template, - 'min': 0, - 'max': 1 - }); + else { + if (string.includes(':')) { + eventType = string.split(':')[0]; + eventName = string.split(':')[1]; + } + else { + eventType = eventString; + eventName = ''; + } + returnValue.push({ + 'eventType': eventType, + 'eventName': eventName, + 'templateFull': template, + 'min': 0, + 'max': 1 + }); + } string = string.replace('[' + template + ']', ''); } return returnValue; @@ -142,7 +156,7 @@ function midiEvent(type, data) { if (result.popup) { switch (type) { case 'noteon': - chrome.runtime.sendMessage({ type: 'midiEvent', data: data.note.name }); + chrome.runtime.sendMessage({ type: 'midiEvent', data: data.note.number }); break; case 'controlchange': chrome.runtime.sendMessage({ type: 'midiEvent', data: data.controller.name }); @@ -156,15 +170,15 @@ function midiEvent(type, data) { midiValue = data.value; templates = templateToDict(event['value']); templates.forEach(template => { - midiValue =(template['min'] + ((template['max']-template['min'])*midiValue)); - if (type == 'noteon' && template['eventType'] == 'noteon' && template['eventName'] == data.note.name) { + midiValue = (template['min'] + ((template['max'] - template['min']) * midiValue)); + if (type == 'noteon' && template['eventType'] == 'note' && template['eventName'] == data.note.number) { value = event['value'].replace('[' + template['templateFull'] + ']', midiValue); let els = document.querySelectorAll(event['selector']); els.forEach(e => { 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); let els = document.querySelectorAll(event['selector']); els.forEach(e => { @@ -390,16 +404,14 @@ function audioEvent() { var dataArray = new Uint8Array(bufferLength); analyser.getByteFrequencyData(dataArray); const presets = { - bass: [20, 250], - lowMid: [250, 500], + low: [20, 250], + lomi: [250, 500], mid: [500, 2e3], - highMid: [2e3, 4e3], - treble: [4e3, 16e3] + mihi: [2e3, 4e3], + hi: [4e3, 16e3] } var startFreq, endFreq, startBin, endBin, energy; - - energies = []; Object.keys(presets).forEach(key => { [startFreq, endFreq] = presets[key]; @@ -420,7 +432,7 @@ function audioEvent() { } audioSample.shift(); audioSample.push(meter.volume); - + console.log(audioEvents); audioEvents.forEach(event => { templates = templateToDict(event['value']); value = event['value']; @@ -431,22 +443,21 @@ function audioEvent() { min = 1; } Object.keys(presets).forEach(preset => { - if (template['eventType'] == 'energy' && template['eventName'] == preset) { + if (template['eventType'] == preset) { 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; 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; value = value.replace('[' + template['templateFull'] + ']', ''); } - if (attack && template['eventType'] == 'noteon' && template['eventName'] == 'attack') { + if (attack && template['eventType'] == 'attack') { eventIn = true; value = value.replace('[' + template['templateFull'] + ']', ''); } @@ -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); if (audio) { rafID = window.requestAnimationFrame(audioEvent); diff --git a/main.js b/main.js index 704d553..7bb92f1 100644 --- a/main.js +++ b/main.js @@ -15,29 +15,31 @@ function loadEditor() { getCompletions: (editor, session, pos, prefix, callback) => { // note, won't fire if caret is at a word that does not have these letters callback(null, [ - { value: '[audio.meter.volume,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: '[audio.energy.mid,0,1]', score: 1, meta: 'Audio energy mid between 0 and 1.' }, - { value: '[audio.energy.treble,0,1]', score: 1, meta: 'Audio energy treble between 0 and 1.' }, - { value: '[audio.noteon.C]', score: 1, meta: 'Audio note C' }, - { value: '[audio.noteon.C#]', score: 1, meta: 'Audio note C#' }, - { value: '[audio.noteon.D]', score: 1, meta: 'Audio note D' }, - { value: '[audio.noteon.D#]', score: 1, meta: 'Audio note D#' }, - { value: '[audio.noteon.E]', score: 1, meta: 'Audio note E' }, - { value: '[audio.noteon.F]', score: 1, meta: 'Audio note F' }, - { value: '[audio.noteon.F#]', score: 1, meta: 'Audio note F#' }, - { value: '[audio.noteon.G]', score: 1, meta: 'Audio note G' }, - { value: '[audio.noteon.G#]', score: 1, meta: 'Audio note G#' }, - { value: '[audio.noteon.A]', score: 1, meta: 'Audio note A' }, - { value: '[audio.noteon.A#]', score: 1, meta: 'Audio note A#' }, - { value: '[audio.noteon.B]', score: 1, meta: 'Audio note B' }, - { value: '[midi.noteon.C,0,1]', score: 1, meta: 'MIDI Note C between 0 and 1.' }, - { value: '[midi.noteon.D,0,1]', score: 1, meta: 'MIDI Note D between 0 and 1.' }, - { value: '[midi.noteon.E,0,1]', score: 1, meta: 'MIDI Note E between 0 and 1.' }, - { value: '[midi.noteon.F,0,1]', score: 1, meta: 'MIDI Note F between 0 and 1.' }, - { value: '[midi.noteon.G,0,1]', score: 1, meta: 'MIDI Note G between 0 and 1.' }, - { value: '[midi.noteon.A,0,1]', score: 1, meta: 'MIDI Note A between 0 and 1.' }, - { value: '[midi.noteon.B,0,1]', score: 1, meta: 'MIDI Note B between 0 and 1.' }, + { value: '[loud,0,1]', score: 1, meta: 'Audio meter between 0 and 1.' }, + { value: '[low,0,1]', score: 1, meta: 'Audio energy low between 0 and 1.' }, + { value: '[lomi,0,1]', score: 1, meta: 'Audio energy low-mid between 0 and 1.' }, + { value: '[mid,0,1]', score: 1, meta: 'Audio energy mid between 0 and 1.' }, + { value: '[mihi,0,1]', score: 1, meta: 'Audio energy mid-high between 0 and 1.' }, + { value: '[hi,0,1]', score: 1, meta: 'Audio energy treble between 0 and 1.' }, + { value: '[onset:C]', score: 1, meta: 'Audio note C' }, + { value: '[onset:C#]', score: 1, meta: 'Audio note C#' }, + { value: '[onset:D]', score: 1, meta: 'Audio note D' }, + { value: '[onset:D#]', score: 1, meta: 'Audio note D#' }, + { value: '[onset:E]', score: 1, meta: 'Audio note E' }, + { value: '[onset:F]', score: 1, meta: 'Audio note F' }, + { value: '[onset:F#]', score: 1, meta: 'Audio note F#' }, + { value: '[onset:G]', score: 1, meta: 'Audio note G' }, + { value: '[onset:G#]', score: 1, meta: 'Audio note G#' }, + { value: '[onset:A]', score: 1, meta: 'Audio note A' }, + { value: '[onset:A#]', score: 1, meta: 'Audio note A#' }, + { value: '[onset:B]', score: 1, meta: 'Audio note B' }, + { value: '[note:24,0,1]', score: 1, meta: 'MIDI Note C between 0 and 1.' }, + { value: '[note:26,0,1]', score: 1, meta: 'MIDI Note D between 0 and 1.' }, + { value: '[note:28,0,1]', score: 1, meta: 'MIDI Note E between 0 and 1.' }, + { value: '[note:29,0,1]', score: 1, meta: 'MIDI Note F 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.' }, ]); }, }], -- GitLab