Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made multichannel-to-equave settings and color mapping dependent on mode #657

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ function sendNoteOn(frequency: number, rawAttack: number) {
}

function midiNoteOn(index: number, rawAttack?: number, channel?: number) {
const multichannel = midi.multichannelToEquave

// in multichannel-to-equave mode calculate an offset based on the incoming channel
if (midi.multichannelToEquave && channel !== undefined) {
if (multichannel && channel !== undefined) {
let offset =
mmod(
channel - midi.multichannelCenter + midi.multichannelEquavesDown,
Expand All @@ -99,7 +101,7 @@ function midiNoteOn(index: number, rawAttack?: number, channel?: number) {
const whiteMode = midi.whiteMode
const indices = scale.whiteIndices

if (whiteMode === 'off') {
if (whiteMode === 'off' || multichannel) {
tuningTableKeyOn(index)
} else if (whiteMode === 'simple') {
if (info.whiteNumber === undefined) {
Expand Down Expand Up @@ -156,7 +158,7 @@ function midiNoteOn(index: number, rawAttack?: number, channel?: number) {
if (!midi.velocityOn) {
rawRelease = 80
}
if (whiteMode === 'simple') {
if (whiteMode === 'simple' || multichannel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is on me for writing bad code in the first place. Enough churn. I'll fix it on main.

if (info.whiteNumber !== undefined) {
tuningTableKeyOff(info.whiteNumber)
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/MidiPiano.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const props = defineProps<{
baseMidiNote: number
whiteModeOffset: number
midiWhiteMode: 'off' | 'simple' | 'blackAverage' | 'keyColors'
multichannel: boolean
keyColors: string[]
activeKeys: Set<number>
}>()
Expand All @@ -30,7 +31,7 @@ const whiteIndices = computed(() => computeWhiteIndices(props.baseMidiNote, prop

function keyLabel(chromaticNumber: number) {
const info = midiKeyInfo(chromaticNumber)
if (props.midiWhiteMode === 'off') {
if (props.midiWhiteMode === 'off' || props.multichannel) {
return [(chromaticNumber - props.baseMidiNote).toString()]
} else if (props.midiWhiteMode === 'simple') {
if (info.whiteNumber !== undefined) {
Expand Down
116 changes: 63 additions & 53 deletions src/views/MidiView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,67 +186,77 @@ onUnmounted(() => {
<label for="multichannel">Multichannel-to-equave</label>
</div>
</div>
<label>Settings for multichannel-to-equave mode</label>
<div class="control multichannel-input-container">
<div>
Center channel
<input
id="multichannel-center"
class="control"
type="number"
min="1"
max="16"
v-model="midi.multichannelCenter"
/>
</div>
<div>
Total equaves
<input
id="multichannel-num-equaves"
class="control"
type="number"
min="1"
max="16"
v-model="midi.multichannelNumEquaves"
/>
<template v-if="midi.multichannelToEquave">
<label>Settings for multichannel-to-equave mode</label>
<div class="control multichannel-input-container">
<div>
Center channel
<input
id="multichannel-center"
class="control"
type="number"
min="1"
max="16"
v-model="midi.multichannelCenter"
/>
</div>
<div>
Total equaves
<input
id="multichannel-num-equaves"
class="control"
type="number"
min="1"
max="16"
v-model="midi.multichannelNumEquaves"
/>
</div>
<div>
Equaves down
<input
id="multichannel-equaves-down"
class="control"
type="number"
min="0"
max="15"
v-model="midi.multichannelEquavesDown"
/>
</div>
</div>
<div>
Equaves down
<input
id="multichannel-equaves-down"
class="control"
type="number"
min="0"
max="15"
v-model="midi.multichannelEquavesDown"
/>
</template>
<template v-if="!midi.multichannelToEquave">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a v-else but then the template becomes more rigid. Maybe two separate v-ifs is better. Just wanted to point out the syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I noticed that possibility this morning while looking around other places where v-if pops up

<div class="control radio-group">
<label>Color mapping</label>
<span>
<input type="radio" id="white-off" value="off" v-model="midi.whiteMode" />
<label for="white-off">Chromatic</label>
</span>
<span>
<input type="radio" id="white-simple" value="simple" v-model="midi.whiteMode" />
<label for="white-simple">White only</label>
</span>
<span>
<input
type="radio"
id="white-black"
value="blackAverage"
v-model="midi.whiteMode"
/>
<label for="white-black">White w/ interpolation</label>
</span>
<span>
<input type="radio" id="white-color" value="keyColors" v-model="midi.whiteMode" />
<label for="white-color">White key to white color</label>
</span>
</div>
</div>
<div class="control radio-group">
<label>Color mapping</label>
<span>
<input type="radio" id="white-off" value="off" v-model="midi.whiteMode" />
<label for="white-off">Chromatic</label>
</span>
<span>
<input type="radio" id="white-simple" value="simple" v-model="midi.whiteMode" />
<label for="white-simple">White only</label>
</span>
<span>
<input type="radio" id="white-black" value="blackAverage" v-model="midi.whiteMode" />
<label for="white-black">White w/ interpolation</label>
</span>
<span>
<input type="radio" id="white-color" value="keyColors" v-model="midi.whiteMode" />
<label for="white-color">White key to white color</label>
</span>
</div>
</template>
</div>
<div class="piano-container">
<MidiPiano
:whiteModeOffset="scale.whiteModeOffset"
:baseMidiNote="scale.baseMidiNote"
:midiWhiteMode="midi.whiteMode"
:multichannel="midi.multichannelToEquave"
:keyColors="scale.colors"
:activeKeys="activeKeys"
/>
Expand Down
Loading