Skip to content

Commit 5a6eb05

Browse files
authored
Merge pull request #1282 from intechstudio/bug/ReleaseFixes3
Release Fixes (Part 3)
2 parents f0cbd2a + 5d84848 commit 5a6eb05

2 files changed

Lines changed: 122 additions & 92 deletions

File tree

src/renderer/config-blocks/Midi.svelte

Lines changed: 119 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,28 @@
4646
<script lang="ts">
4747
import { createEventDispatcher } from "svelte";
4848
import { MeltCombo } from "@intechstudio/grid-uikit";
49-
import { GridScript } from "@intechstudio/grid-protocol";
49+
import {
50+
ElementType,
51+
EventType,
52+
GridScript,
53+
NumberToEventType,
54+
} from "@intechstudio/grid-protocol";
5055
import { midiCC } from "./_midi.js";
5156
import { Script } from "./_script_parsers.js";
5257
import { LocalDefinitions } from "../runtime/runtime.store";
53-
import { GridAction, GridEvent } from "./../runtime/runtime";
58+
import { GridAction, GridElement, GridEvent } from "./../runtime/runtime";
5459
import SendFeedback from "../main/user-interface/SendFeedback.svelte";
5560
import TabButton from "../main/user-interface/TabButton.svelte";
5661
import { MusicalNotes } from "../main/panels/MidiMonitor/MidiMonitor.store";
5762
import { Validator } from "./validators";
5863
import { valid } from "semver";
5964
import { Grid } from "../lib/_utils.js";
65+
import ActionHelper from "../main/panels/configuration/components/ActionHelper.svelte";
6066
6167
export let config: GridAction;
6268
6369
let event = config.parent as GridEvent;
70+
let element = event.parent as GridElement;
6471
6572
const dispatch = createEventDispatcher();
6673
@@ -117,117 +124,139 @@
117124
});
118125
}
119126
120-
const channels = (length) => {
121-
let arr = [];
122-
for (let i = 0; i < length; i++) {
123-
arr[i] = { value: i, info: `Channel ${i + 1}` };
124-
}
125-
return arr;
126-
};
127+
$: if ($event) {
128+
renderSuggestions();
129+
}
130+
131+
const tabs = [
132+
{ name: "MIDI", short: "gms" },
133+
{ name: "14 bit MIDI", short: "gmsh" },
134+
{ name: "SysEX", short: "gmss" },
135+
{ name: "NRPN MIDI", short: "gmnp" },
136+
];
137+
138+
type SuggestionValue = { value: string; info: string; key: string };
139+
140+
// --- helpers ---
141+
const makeAuto = (info: string, key = "auto"): SuggestionValue => ({
142+
value: "-1",
143+
info,
144+
key,
145+
});
146+
147+
const makeChannels = (n: number) =>
148+
Array.from({ length: n }, (_, i) => ({
149+
value: String(i),
150+
info: `Channel ${i + 1}`,
151+
key: `ch_${i}`,
152+
}));
127153
128-
const _suggestions = [
129-
// channels
130-
[...channels(16)],
131-
// commands
154+
const makeCCs = () =>
155+
Object.entries(midiCC).map(([value, info]) => ({
156+
value,
157+
info,
158+
key: `cc_${value}`,
159+
}));
160+
161+
const makeNotes = () =>
162+
Array.from({ length: 128 }, (_, i) => ({
163+
value: String(i),
164+
info: MusicalNotes.FromInt(i),
165+
key: `note_${i}`,
166+
}));
167+
168+
const baseSuggestions: Array<SuggestionValue[]> = [
169+
[
170+
makeAuto(
171+
`Auto (${Grid.Auto.getMidi(config, Grid.Auto.Value.MIDI_CHANNEL)})`,
172+
),
173+
...makeChannels(16),
174+
],
132175
[
133176
{ value: "176", info: "Control Change", key: "control_change_messages" },
134177
{ value: "144", info: "Note On", key: "note_on_event" },
135178
{ value: "128", info: "Note Off", key: "note_off_event" },
136179
{ value: "192", info: "Program Change", key: "program_change_messages" },
137180
],
138-
// param 1
139-
[],
140-
// param 2
141-
[
142-
//{value: '', info: 'to do...'}
143-
],
181+
[], // param1 (dynamic)
182+
[makeAuto("Auto")],
144183
];
145184
146-
let suggestions = [];
147-
let suggestionsAuto = [];
148-
149-
$: if ($event) {
150-
renderSuggestions();
151-
}
185+
let suggestions: SuggestionValue[][] = [];
152186
153187
function renderSuggestions() {
154-
// removed ?. as terser didn't work
155-
let selectedCommand = _suggestions[1].find(
156-
(s) => s.value == scriptSegments[1],
188+
const currentCommand = Grid.Auto.getMidi(
189+
config,
190+
Grid.Auto.Value.MIDI_COMMAND,
157191
);
158-
if (selectedCommand) {
159-
selectedCommand = selectedCommand.key;
160-
} else {
161-
selectedCommand = "control_change_messages";
162-
}
163192
164-
try {
165-
let param_1: any[] = [];
166-
if (selectedCommand === "control_change_messages") {
167-
param_1 = Object.entries(midiCC).map(([value, info]) => ({
168-
value: Number(value),
169-
info,
170-
}));
171-
} else if (
172-
["note_on_event", "note_off_event"].includes(selectedCommand)
173-
) {
174-
param_1 = [...Array(128).keys()].map((e) => {
175-
return { value: String(e), info: MusicalNotes.FromInt(e) };
176-
});
177-
}
193+
// find corresponding command once
194+
const commandEntry = baseSuggestions[1].find(
195+
(e) => +e.value === currentCommand,
196+
);
197+
const autoCommand = makeAuto(
198+
`Auto (${commandEntry?.info ?? "?"})`,
199+
commandEntry?.key ?? "control_change_messages",
200+
);
178201
179-
suggestionsAuto = [
180-
{
181-
value: "-1",
182-
info: `Auto (${Grid.Auto.getMidi(config, Grid.Auto.Value.MIDI_CHANNEL)})`,
183-
key: "auto",
184-
},
185-
{
186-
value: "-1",
187-
info: `Auto (${Grid.Auto.getMidi(config, Grid.Auto.Value.MIDI_COMMAND)})`,
188-
key: "auto",
189-
},
190-
{
191-
value: "-1",
192-
info: `Auto (${Grid.Auto.getMidi(config, Grid.Auto.Value.MIDI_P1)})`,
193-
key: "auto",
194-
},
195-
{
196-
value: "-1",
197-
info: `Auto`,
198-
key: "auto",
199-
},
200-
];
201-
suggestions = [
202-
[..._suggestions[0]],
203-
[..._suggestions[1]],
204-
[...param_1],
205-
[..._suggestions[3]],
206-
];
207-
} catch (error) {
208-
console.warn("error while creating midi suggetions");
209-
suggestions = _suggestions;
202+
const selectedCommand =
203+
[autoCommand, ...baseSuggestions[1]].find(
204+
(s) => s.value == scriptSegments[1],
205+
)?.key ?? "control_change_messages";
206+
207+
// param1 depends on selected command
208+
let param1: SuggestionValue[];
209+
switch (selectedCommand) {
210+
case "control_change_messages":
211+
param1 = [
212+
makeAuto(
213+
`Auto (${Grid.Auto.getMidi(config, Grid.Auto.Value.MIDI_P1)})`,
214+
),
215+
...makeCCs(),
216+
];
217+
break;
218+
case "note_on_event":
219+
case "note_off_event":
220+
const autoNote = Grid.Auto.getMidi(config, Grid.Auto.Value.MIDI_P1);
221+
param1 = [
222+
makeAuto(`Auto (${MusicalNotes.FromInt(autoNote)})`),
223+
...makeNotes(),
224+
];
225+
break;
226+
default:
227+
param1 = [];
210228
}
211229
230+
// fetch local definitions
212231
const actions = $event.config;
213232
const index = actions.findIndex((e) => e.id === config.id);
214233
const localDefinitions = LocalDefinitions.getFrom({
215234
configs: actions,
216-
index: index,
235+
index,
217236
});
218-
suggestions = suggestions.map((s, index) => [
219-
suggestionsAuto[index],
220-
...localDefinitions,
221-
...s,
222-
]);
237+
238+
// assemble suggestions with "auto" always first
239+
suggestions = [
240+
[
241+
baseSuggestions[0][0],
242+
...localDefinitions,
243+
...baseSuggestions[0].slice(1),
244+
], // channels
245+
[autoCommand, ...localDefinitions, ...baseSuggestions[1]], // commands
246+
param1.length > 0
247+
? [param1[0], ...localDefinitions, ...param1.slice(1)]
248+
: [...localDefinitions], // param1
249+
[
250+
baseSuggestions[3][0],
251+
...localDefinitions,
252+
...baseSuggestions[3].slice(1),
253+
], // param2
254+
];
223255
}
224256
225-
const tabs = [
226-
{ name: "MIDI", short: "gms" },
227-
{ name: "14 bit MIDI", short: "gmsh" },
228-
{ name: "SysEX", short: "gmss" },
229-
{ name: "NRPN MIDI", short: "gmnp" },
230-
];
257+
$: if ($event) {
258+
renderSuggestions();
259+
}
231260
232261
function handleTabButtonClicked(element) {
233262
dispatch("replace", { short: element.short });

src/renderer/config-blocks/SettingsButton.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<script lang="ts">
2727
import { createEventDispatcher } from "svelte";
28-
import { GridScript } from "@intechstudio/grid-protocol";
28+
import { ElementType, GridScript } from "@intechstudio/grid-protocol";
2929
import { Validator } from "./validators";
3030
import {
3131
MeltCheckbox,
@@ -126,7 +126,8 @@
126126
const suggestions: Array<MeltComboSuggestion[]> = [
127127
[
128128
...Grid.Array.when<MeltComboSuggestion>(
129-
[27, 91, 59, 123, 131, 67, 75].includes(module.hwcfg),
129+
[27, 91, 59, 123, 131, 67, 75].includes(module.hwcfg) &&
130+
element.type === ElementType.BUTTON,
130131
[
131132
{ value: "-2", info: "Pressure" },
132133
{ value: "-1", info: "Velocity" },

0 commit comments

Comments
 (0)