Skip to content

Commit f74b85d

Browse files
committed
Indicate muted state in mixer and sequencer
1 parent d436064 commit f74b85d

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

src/audio/Player.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ export class Player extends EventTarget {
242242
}
243243

244244
for (let ev of patternEvents) {
245+
if (ev.instrumenteer.muted) {
246+
continue;
247+
}
248+
245249
const evTime = ev.time * (durationSec / durationBeats);
246250
const playTime = this.startTime + this.currentTime + evTime;
247251
if (ev.type === "midinote") {

src/commands/SequenceEditor/Register.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AddColumnCommand } from "./AddColumnCommand";
33
import { CopyCommand } from "./CopyCommand";
44
import { CutCommand } from "./CutCommand";
55
import { DeleteColumnCommand } from "./DeleteColumnCommand";
6+
import { MuteCommand } from "./MuteCommand";
67
import { PasteCommand } from "./PasteCommand";
78
import { SetLoopEndCommand } from "./SetLoopEndCommand";
89
import { SetLoopStartCommand } from "./SetLoopStartCommand";
@@ -16,6 +17,7 @@ export function registerSequenceEditorCommands(component: SequencePanel) {
1617
component.registerCommand("delete-column", "hgi-stroke hgi-minus-sign", null, new DeleteColumnCommand(component));
1718
component.registerCommand("set-loop-start", null, null, new SetLoopStartCommand(component));
1819
component.registerCommand("set-loop-end", null, null, new SetLoopEndCommand(component));
20+
component.registerCommand("mute", null, "Toggle Mute", new MuteCommand(component));
1921

2022
// component.registerHotkey("CTRL+A", "select-all");
2123
component.registerHotkey("CTRL++", "add-column");
@@ -24,5 +26,5 @@ export function registerSequenceEditorCommands(component: SequencePanel) {
2426
component.registerHotkey("CTRL+C", "copy");
2527
component.registerHotkey("CTRL+V", "paste");
2628
component.registerHotkey("CTRL+B", "set-loop-start");
27-
component.registerHotkey("CTRL+E", "set-loop-end");
29+
component.registerHotkey("CTRL+M", "mute");
2830
}

src/components/MixerCanvas.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { PinsPanel } from "./PinsPanel";
66
import { MenuItem } from "../menu/menu";
77
import { getNoteForKey } from "./PatternEditorHelper";
88

9+
function colorWithBrightness(r: number, g: number, b: number, brightness: number) {
10+
const red = Math.max(0, Math.min(255, Math.round(r * brightness)));
11+
const green = Math.max(0, Math.min(255, Math.round(g * brightness)));
12+
const blue = Math.max(0, Math.min(255, Math.round(b * brightness)));
13+
return "rgb(" + red + ", " + green + ", " + blue + ")";
14+
}
15+
916
const boxWidth = 100;
1017
const boxHeight = 61; // 1.618
1118
const arrowSize = 10;
@@ -170,6 +177,7 @@ export class MixerCanvas implements IComponent {
170177
this.app.song.addEventListener("createInstrument", this.onResize);
171178
this.app.song.addEventListener("updateInstrument", this.onResize);
172179
this.app.song.addEventListener("deleteInstrument", this.onResize);
180+
this.app.song.addEventListener("setInstrumentMuted", this.onResize);
173181
this.app.song.addEventListener("createConnection", this.onResize);
174182
this.app.song.addEventListener("deleteConnection", this.onResize);
175183
};
@@ -178,6 +186,7 @@ export class MixerCanvas implements IComponent {
178186
this.app.song.removeEventListener("createInstrument", this.onResize);
179187
this.app.song.removeEventListener("updateInstrument", this.onResize);
180188
this.app.song.removeEventListener("deleteInstrument", this.onResize);
189+
this.app.song.removeEventListener("setInstrumentMuted", this.onResize);
181190
this.app.song.removeEventListener("createConnection", this.onResize);
182191
this.app.song.removeEventListener("deleteConnection", this.onResize);
183192
};
@@ -469,25 +478,28 @@ export class MixerCanvas implements IComponent {
469478
ctx.lineWidth = 3;
470479
}
471480

472-
const hasIn = this.app.song.connections.find(c => c.to === instrument);
473-
const hasOut = this.app.song.connections.find(c => c.from === instrument);
481+
const instrumenteer = this.app.playerSongAdapter.instrumentMap.get(instrument);
482+
const hasIn = !!instrumenteer.instrument.inputNode;
483+
const hasOut = !!instrumenteer.instrument.outputNode;
484+
const brightness = instrument.muted ? 0.6 : 1.0;
474485
if (hasIn && !hasOut) {
475-
ctx.fillStyle = "#5C704C";
486+
ctx.fillStyle = colorWithBrightness(92, 112, 76, brightness);
476487
} else if (hasIn && hasOut) {
477-
ctx.fillStyle = "#101010";
488+
ctx.fillStyle = colorWithBrightness(68, 68, 68, brightness);
478489
} else {
479-
ctx.fillStyle = "#2A614B";
490+
ctx.fillStyle = colorWithBrightness(42, 97, 75, brightness);
480491
}
481492

482493
ctx.strokeStyle = "#000";
483494

484495
ctx.fillRect(c[0] - boxWidth / 2, c[1] - boxHeight / 2, boxWidth, boxHeight);
485496
ctx.strokeRect(c[0] - boxWidth / 2, c[1] - boxHeight / 2, boxWidth, boxHeight);
486497

487-
const mt = ctx.measureText(instrument.name);
498+
const name = instrument.muted ? "(" + instrument.name + ")" : instrument.name;
499+
const mt = ctx.measureText(name);
488500

489501
ctx.fillStyle = "#FFF";
490-
ctx.fillText(instrument.name, c[0] - mt.width / 2, c[1] + mt.fontBoundingBoxAscent - fontHeight / 2 );
502+
ctx.fillText(name, c[0] - mt.width / 2, c[1] + mt.fontBoundingBoxAscent - fontHeight / 2 );
491503

492504
ctx.restore();
493505

src/components/SequenceEditorCanvas.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export class SequenceEditorCanvas extends EventTarget implements IComponent {
113113
this.app.song.addEventListener("playing", this.onPlaying);
114114
this.app.song.addEventListener("stopped", this.onStopped);
115115
this.app.song.addEventListener("updateDocument", this.onResize);
116+
this.app.song.addEventListener("setInstrumentMuted", this.onResize);
116117
this.app.song.addEventListener("createSequenceColumn", this.onResize);
117118
this.app.song.addEventListener("deleteSequenceColumn", this.onResize);
118119
this.app.song.addEventListener("createSequenceEvent", this.onResize);
@@ -124,6 +125,7 @@ export class SequenceEditorCanvas extends EventTarget implements IComponent {
124125
this.app.song.removeEventListener("playing", this.onPlaying);
125126
this.app.song.removeEventListener("stopped", this.onStopped);
126127
this.app.song.removeEventListener("updateDocument", this.onResize);
128+
this.app.song.removeEventListener("setInstrumentMuted", this.onResize);
127129
this.app.song.removeEventListener("createSequenceColumn", this.onResize);
128130
this.app.song.removeEventListener("deleteSequenceColumn", this.onResize);
129131
this.app.song.removeEventListener("createSequenceEvent", this.onResize);
@@ -401,7 +403,8 @@ export class SequenceEditorCanvas extends EventTarget implements IComponent {
401403
ctx.lineTo(sequenceX + columnWidth, this.canvas.height);
402404
ctx.stroke();
403405

404-
ctx.fillText(sequenceColumn.instrument.name, sequenceX, this.fontEm.fontBoundingBoxAscent, columnWidth);
406+
const name = sequenceColumn.instrument.muted ? "(" + sequenceColumn.instrument.name + ")" : sequenceColumn.instrument.name;
407+
ctx.fillText(name, sequenceX, this.fontEm.fontBoundingBoxAscent, columnWidth);
405408

406409
// Clip header
407410
ctx.save();

0 commit comments

Comments
 (0)