Skip to content

Commit

Permalink
fix preset selectors handling
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisgeorgy committed Mar 18, 2019
1 parent 1f05006 commit 2ee2414
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 49 deletions.
26 changes: 12 additions & 14 deletions internals.md
Expand Up @@ -35,11 +35,10 @@ MIDI IN:
if SYSEX_PRESET:
resetExp
updateUI
updateMeta
showPreset
setPresetClean
add .sel if pc>0
add .on if communication ok
updatePresetSelector
setPresetClean
add .sel if pc>0
add .on if communication ok
updateControls
if SYSEX_GLOBALS:
updateGlobalSettings
Expand All @@ -61,10 +60,10 @@ MIDI DEVICE:
connectInputDevice
disconnectInputPort
remove listeners
showPreset
updatePresetSelector
connectInputPort
setMidiInputPort
showPreset
updatePresetSelector
syncIfNoPreset
if preset === 0
requestPreset
Expand All @@ -84,20 +83,19 @@ MIDI DEVICE:
initFromBookmark
resetExp
updateUI
updateMeta
showPreset
setPresetClean
add .sel if pc>0
add .on if communication ok
updatePresetSelector
setPresetClean
add .sel if pc>0
add .on if communication ok
updateControls
on disconnected:
deviceDisconnected
port is input:
disconnectInputPort
remove listeners
showPreset
updatePresetSelector
port is output:
disconnectOutputPort
showPreset
updatePresetSelector
updateSelectDeviceList
2 changes: 1 addition & 1 deletion src/debug.js
@@ -1,5 +1,5 @@

export const TRACE = false;
export const TRACE = true;

export function log() {
if (TRACE) console.log(...arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Expand Up @@ -374,7 +374,7 @@
<div id="exp-close" class="exp-switch"><div class="btx" id="exp-close-bt" title="Click to switch to edit the EXP (toe-down) values">down</div></div>
<div id="exp-open">toe up</div>
<div id="cc-4-value" class="slider-value"></div>
<div id="exp-copy" class="btx" title="Click to copy the toe-up (normal) values to the tow-down values.">copy</div>
<div id="exp-copy" class="btx" title="Click to copy the toe-up (normal) values to the toe-down values.">copy</div>
</div>
</div>

Expand Down
10 changes: 5 additions & 5 deletions src/main.js
Expand Up @@ -19,7 +19,7 @@ import "./css/main.css";
import "./css/zoom.css";
import "./css/grid-default.css";
import "./css/grid-global-settings.css";
import {setPresetDirty, showPreset} from "./ui_presets";
import {setPresetDirty, updatePresetSelector} from "./ui_presets";
import * as Utils from "./utils";
import {initZoom} from "./ui_zoom";

Expand Down Expand Up @@ -96,7 +96,7 @@ function connectInputPort(input) {

log(`%cconnectInputPort: ${input.name} is now listening on channel ${preferences.midi_channel}`, "color: orange; font-weight: bold");
setCommunicationStatus(true);
showPreset();
updatePresetSelector();
appendMessage(`Input ${input.name} connected on MIDI channel ${preferences.midi_channel}.`);
}

Expand All @@ -107,7 +107,7 @@ function disconnectInputPort() {
p.removeListener(); // remove all listeners for all channels
setMidiInputPort(null);
setCommunicationStatus(false);
showPreset();
updatePresetSelector();
appendMessage(`Input disconnected.`);
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ function connectOutputPort(output) {
log("connectOutputPort");
setMidiOutputPort(output);
log(`%cconnectOutputPort: ${output.name} can now be used to send data on channel ${preferences.midi_channel}`, "color: orange; font-weight: bold");
showPreset();
updatePresetSelector();
appendMessage(`Output ${output.name} connected on MIDI channel ${preferences.midi_channel}.`);
}

Expand All @@ -170,7 +170,7 @@ function disconnectOutputPort() {
log("disconnectOutputPort()");
setMidiOutputPort(null);
log("disconnectOutputPort: connectOutputPort: midi_output can not be used anymore");
showPreset();
updatePresetSelector();
appendMessage(`Output disconnected.`);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/midi_in.js
@@ -1,5 +1,5 @@
import {showMidiInActivity} from "./ui_midi_activity";
import {showPreset} from "./ui_presets";
import {updatePresetSelector} from "./ui_presets";
import {logIncomingMidiMessage} from "./ui_midi_window";
import {getLastSendTime} from "./midi_out";
import {updateModelAndUI, updateUI} from "./ui";
Expand Down Expand Up @@ -55,7 +55,7 @@ export function handlePC(msg) {
showMidiInActivity();
logIncomingMidiMessage("PC", [msg.value]);
MODEL.setPresetNumber(msg.value);
showPreset();
updatePresetSelector();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/midi_out.js
Expand Up @@ -143,7 +143,7 @@ export function fullUpdateDevice() {
log(`fullUpdateDevice done`);
fullUpdateRunning = false;
if (!silent && midi_output) {
appendMessage("Current settings sent to Enzo.")
appendMessage("Current settings sent to the pedal.")
}
} else {
// log(`fullUpdateDevice: send CC ${i}`);
Expand Down Expand Up @@ -184,11 +184,11 @@ export function sendPC(pc) {
appendMessage(`Preset ${pc} selected.`);

if (!getMidiInputPort()) {
appendMessage("Unable to receive the preset from Enzo.");
appendMessage("Unable to receive the preset from the pedal.");
}

} else {
appendMessage(`Unable to send the PC command to Enzo.`);
appendMessage(`Unable to send the PC command to the pedal.`);
log(`(send program change ${pc})`);
}

Expand Down
16 changes: 4 additions & 12 deletions src/ui.js
@@ -1,5 +1,5 @@
import MODEL from "./model";
import {showPreset, setPresetDirty, setupPresetSelectors} from "./ui_presets";
import {updatePresetSelector, setPresetDirty, setupPresetSelectors} from "./ui_presets";
import {knobs, setupKnobs} from "./ui_knobs";
import {
setupMomentarySwitches,
Expand Down Expand Up @@ -51,7 +51,7 @@ export function handleUserAction(control_type, control_number, value) {
* @param value
* @param mappedValue
*/
export function updateControl(control_type, control_number, value, mappedValue) { //TODO: check that control_number is always an int and not a string
export function updateControl(control_type, control_number, value, mappedValue) {

//FIXME: no need for control_type

Expand All @@ -67,6 +67,7 @@ export function updateControl(control_type, control_number, value, mappedValue)
knobs[id].value = value; //TODO: doesn't the knob update its value itself?
} else {

//TODO: check that control_number is always an int and not a string
const num = parseInt(control_number, 10);

if (/*control_type === "cc" &&*/ num === 4) { //TODO: replace this hack with better code
Expand Down Expand Up @@ -94,7 +95,6 @@ export function updateControl(control_type, control_number, value, mappedValue)
} else if (c.is(".swm")) {
log(`updateControl(${control_type}, ${num}, ${value}) .swm`);
updateMomentaryStompswitch(`${id}-${mappedValue}`, mappedValue);
// log(typeof mappedValue, mappedValue === 0);
// if (mappedValue !== 0) {
// log("will call updateMomentaryStompswitch in 200ms");
setTimeout(() => updateMomentaryStompswitch(`${id}-${mappedValue}`, 0), 200);
Expand Down Expand Up @@ -130,18 +130,11 @@ export function updateControls(onlyTwoValuesControls = false) {
if (TRACE) console.groupEnd();
} // updateControls()

/**
* Update the patch number and patch name displayed in the header.
*/
function updateMeta() {
showPreset();
}

/**
* Update the UI from the MODEL controls values.
*/
export function updateUI() {
updateMeta();
updatePresetSelector();
updateControls();
log("updateUI done");
}
Expand Down Expand Up @@ -243,7 +236,6 @@ export function setupUI(channelSelectionCallback, inputSelectionCallback, output
setupAppPreferences();
setupHelpPanel();
setupMenu();
// setupExp();
setupSelects(channelSelectionCallback, inputSelectionCallback, outputSelectionCallback);
setupKeyboard();

Expand Down
4 changes: 2 additions & 2 deletions src/ui_exp.js
Expand Up @@ -52,7 +52,7 @@ export function toggleExpEditMode() {
updateDevice("cc", MODEL.control_id.exp_pedal, 0);

showExpValues(false);
appendMessage("You are now editing the normal values");
appendMessage("You are now editing the normal values", true);

} else {

Expand All @@ -65,7 +65,7 @@ export function toggleExpEditMode() {
updateDevice("cc", MODEL.control_id.exp_pedal, 127);

showExpValues(true);
appendMessage("You are now editing the EXP (tow-down) values", true);
appendMessage("You are now editing the EXP (toe down) values", true);

}
}
Expand Down
32 changes: 23 additions & 9 deletions src/ui_presets.js
Expand Up @@ -12,6 +12,18 @@ import {getMidiInputPort} from "./midi_in";
The .dirty flag is cleared when we receive a preset (via sysex) or when we load a preset file.
*/

/**
* Remove all flags and highlight color from the preset selectors.
*/
export function resetPresetSelectors() {
log("resetPresetSelectors()");
$(".preset-id").removeClass("dirty on sel");
dirty_cache = false;
}

/**
* Remove any dirty indicator from the preset selectors
*/
export function setPresetClean() {
log("setPresetClean()");
$(".preset-id").removeClass("dirty");
Expand All @@ -20,6 +32,9 @@ export function setPresetClean() {

let dirty_cache = true; // setPresetDirty is called each time a control is modified. This variable is used to minimize the DOM changes.

/**
* Show the dirty indicator on the current preset selector
*/
export function setPresetDirty() {
if (!dirty_cache) {
log("setPresetDirty()");
Expand All @@ -29,22 +44,21 @@ export function setPresetDirty() {
}
}

export function showPreset() {
log("showPreset()");
/**
* Update the preset selector to show the current pedal's preset.
* Highlight the preset selector if the communication is up with the pedal.
*/
export function updatePresetSelector() {
log("updatePresetSelector()");

// const elems = $(".preset-id");
// elems.removeClass("on sel dirty");
// dirty_cache = false; // because we removed .dirty
setPresetClean();
resetPresetSelectors();

const n = MODEL.getPresetNumber();
if (n) {
const e = $(`#pc-${n}`);
e.addClass("sel");
if (getMidiInputPort() && getMidiOutputPort()) {
e.addClass("on");
// } else {
// elems.removeClass("on");
}
}
}
Expand All @@ -56,7 +70,7 @@ export function showPreset() {
export function presetSet(n) {
log(`presetSet(${n})`);
MODEL.setPresetNumber(n);
showPreset();
updatePresetSelector();
sendPC(n);
}

Expand Down

0 comments on commit 2ee2414

Please sign in to comment.