Skip to content

Commit

Permalink
Show pitch associated with MIDI base index
Browse files Browse the repository at this point in the history
ref #795
  • Loading branch information
frostburn committed Jul 29, 2024
1 parent 1f8d903 commit ed28f93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change log

## 3.0.1
* Regression: Show pitch associated with MIDI base index [#795](https://github.com/xenharmonic-devs/scale-workshop/issues/795)

## 3.0.0
* Feature: Core language switched to from [scale-workshop-core](https://github.com/xenharmonic-devs/scale-workshop-core) to [sonic-weave](https://github.com/xenharmonic-devs/sonic-weave)
* Feature: Custom interval labels e.g. `3/2 "my fifth"`
Expand Down
10 changes: 9 additions & 1 deletion src/components/ScaleControls.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useScaleStore } from '@/stores/scale'
import { debounce } from '@/utils'
import { debounce, midiNoteNumberToName } from '@/utils'
import { ref } from 'vue'
import ScaleRule from './ScaleRule.vue'
import palette from '@/character-palette.json'
Expand Down Expand Up @@ -57,6 +57,9 @@ defineExpose({ focus, clearPaletteInfo })
v-model="scale.baseMidiNote"
@input="updateScale()"
/>
<span class="midi-name">{{
midiNoteNumberToName(scale.baseMidiNote, -1, scale.accidentalPreference)
}}</span>
</div>

<div class="control">
Expand Down Expand Up @@ -160,6 +163,11 @@ defineExpose({ focus, clearPaletteInfo })
</template>

<style scoped>
.midi-name {
width: 1em;
margin-left: 0.4em;
margin-right: 0.4em;
}
.info {
height: 3em;
overflow-y: hidden;
Expand Down
14 changes: 11 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,26 @@ export function debounce(func: (...args: any[]) => void, timeout = 300) {
}
}

const MIDI_NOTE_NAMES = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
const MIDI_NOTE_NAMES = ['C', 'C', 'D', 'D', 'E', 'F', 'F', 'G', 'G', 'A', 'A', 'B']

/**
* Convert an integer MIDI note number to a name such as A4.
* @param noteNumber MIDI note number to convert.
* @param octaveOffset Defaults to the English standard: 69 = A4. An offset of zero results in the French standard 69 = A5.
* @returns String representation of the MIDI note number.
*/
export function midiNoteNumberToName(noteNumber: number, octaveOffset = -1) {
export function midiNoteNumberToName(
noteNumber: number,
octaveOffset = -1,
accidentalStyle: AccidentalStyle = 'ASCII'
) {
const remainder = mmod(noteNumber, 12)
const quotient = (noteNumber - remainder) / 12 + octaveOffset
return MIDI_NOTE_NAMES[remainder] + quotient.toString()
const result = MIDI_NOTE_NAMES[remainder] + quotient.toString()
if (accidentalStyle === 'ASCII') {
return result.replace('♮', '').replace('♯', '#')
}
return result
}

export function sanitizeFilename(input: string) {
Expand Down

0 comments on commit ed28f93

Please sign in to comment.