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

Issue #411 #501

Merged
merged 3 commits into from
Nov 29, 2023
Merged

Issue #411 #501

merged 3 commits into from
Nov 29, 2023

Conversation

inthar-raven
Copy link
Contributor

Added radio buttons and the reaction. Using zero-indexing is the default and omits the column of all unisons.

@@ -87,7 +89,8 @@ const matrix = computed(() => {
props.scale.head(MAX_SCALE_SIZE).mergeOptions({
centsFractionDigits: 1,
decimalFractionDigits: 3,
})
}),
1 - (matrixStartIndex.value)
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't call a property something and then pass it as the inverse of that to another function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I have should work fine (for issue #411), though. I am using just "matrixStartIndex.value" in other parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's admittedly a really janky way to not display the zeroth column but just for the zero-indexed option. I should fix that.

@@ -99,10 +102,10 @@ const matrix = computed(() => {
<table>
<tr>
<th></th>
<th v-for="i of Math.min(scale.size, MAX_SCALE_SIZE)" :key="i">
<th v-for="i of Math.min(scale.size-1+matrixStartIndex, MAX_SCALE_SIZE-1)" :key="i">
Copy link
Member

Choose a reason for hiding this comment

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

MAX_SCALE_SIZE is a sanity limit that makes sure the browser doesn't go 💥 . You could rename it to something like MAX_NUM_COLUMNS or something. That -1 should be there on a constant.

src/analysis.ts Outdated
const result = [];
const degrees = [...Array(scale.size + 1).keys()];
const degrees = [...Array(scale.size + 1 - startIndex).keys()];
Copy link
Member

Choose a reason for hiding this comment

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

I know this is my code, but this is no longer an array of degrees.
Just do an extra for loop below and collect stuff into a const row = [] array.

@@ -19,6 +19,8 @@ const props = defineProps<{
}>();

const cellFormat = ref<"best" | "cents" | "decimal">("best");
const indexing = ref<"zero" | "one">("zero");
const matrixStartIndex = computed(() => indexing.value === "one" ? 1 : 0);
Copy link
Member

Choose a reason for hiding this comment

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

To be specific: Swap here, not down there.

Copy link
Member

Choose a reason for hiding this comment

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

Computed properties should be collected together after mutable state.

@frostburn
Copy link
Member

The choice should be persisted

watch(indexing, (newValue) =>
  window.localStorage.setItem("intervalMatrixIndexing", newValue)
);

and the corresponding .getItem(...) ?? "zero" when initializing the ref.

@@ -19,6 +19,8 @@ const props = defineProps<{
}>();

const cellFormat = ref<"best" | "cents" | "decimal">("best");
const intervalMatrixIndexing = ref<"zero" | "one">("zero");
Copy link
Member

Choose a reason for hiding this comment

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

If you want to persist the value you have to use a component prop and drill it back to the app using emits.
Now this line just creates a new local property.

src/App.vue Outdated
@@ -288,6 +289,7 @@ watch(
pingPongFeedback,
pingPongSeparation,
pingPongGain,
intervalMatrixIndexing
Copy link
Member

Choose a reason for hiding this comment

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

You specifically don't want to share your personal preferences with the world.

@frostburn
Copy link
Member

The app doesn't load at all for me now.

src/analysis.ts Outdated
@@ -103,12 +103,12 @@ export function utonalFundamental(frequencies: number[], maxDivisor = 23) {
}

// Interval matrix a.k.a the modes of a scale
export function intervalMatrix(scale: Scale) {
export function intervalMatrix(scale: Scale, startIndex: number) {
Copy link
Member

Choose a reason for hiding this comment

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

This is now an unrelated change that doesn't belong in the scope of this PR.

@frostburn
Copy link
Member

Now it works on my end. What's the intended behaviour?
I'm seeing that toggling the radio button simply adds one to the header row. If that's all that this is supposed to do, then clean the code to only do that. No need for fancy computes or anything.

src/App.vue Outdated
@@ -120,6 +120,7 @@ const centsFractionDigits = ref(3);
const decimalFractionDigits = ref(5);
const showVirtualQwerty = ref(false);
const midiOctaveOffset = ref(-1);
const intervalMatrixIndexing = ref<"zero" | "one">("zero");
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 replaced with a number called intervalMatrixIndexOffset that gets added to the headers if that's the intended effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my previous iterations of attempting that, it seems the radio buttons don't want me to make their associated type a number instead of a radio:

Internal server error: Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.
Plugin: vite:vue
File: /home/inthar/Downloads/scale-workshop-main/src/views/AnalysisView.vue
160| <input
161| type="number"
162| id="indexing-zero"
| ^
163| value="0"
164| v-model="intervalMatrixIndexing"
at Object.createCompilerError (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:19:19)
at createDOMCompilerError (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js:2483:25)
at checkDuplicatedValue (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js:2547:29)
at transformModel (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.js:2579:29)
at buildProps (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:4777:48)
at Array.postTransformElement (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:4374:38)
at traverseNode (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2225:19)
at traverseChildren (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2167:9)
at traverseNode (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2218:13)
at traverseChildren (/home/inthar/Downloads/scale-workshop-main/node_modules/@vue/compiler-core/dist/compiler-core.cjs.js:2167:9)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's one of these things that seem like they ought to work but don't.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, you need an auxillary ref and a watcher if you want to use v-model it's better to just emit the correct values from the radio buttons directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What can I use to label the data instead of a v-model?

@@ -87,7 +97,8 @@ const matrix = computed(() => {
props.scale.head(MAX_SCALE_SIZE).mergeOptions({
centsFractionDigits: 1,
decimalFractionDigits: 3,
})
}),
0
Copy link
Member

Choose a reason for hiding this comment

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

This whole change should be reverted as I misread your intention when suggesting it.

@frostburn
Copy link
Member

This is now 13 commits long. They should all be squashed into one so that we get a readable commit history in main.

@@ -105,10 +105,10 @@ export function utonalFundamental(frequencies: number[], maxDivisor = 23) {
// Interval matrix a.k.a the modes of a scale
export function intervalMatrix(scale: Scale) {
const result = [];
const degrees = [...Array(scale.size + 1).keys()];
const columns = [...Array(scale.size + 1).keys()];
Copy link
Member

Choose a reason for hiding this comment

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

A little unrelated, but OK...

src/App.vue Outdated
@@ -783,7 +784,9 @@ onMounted(() => {
if ("midiOctaveOffset" in storage) {
midiOctaveOffset.value = parseInt(storage.getItem("midiOctaveOffset")!);
}

if ("intervalMatrixIndexing" in storage) {
intervalMatrixIndexing.value = parseInt(storage.getItem("intervalMatrixIndexing")!);
Copy link
Member

Choose a reason for hiding this comment

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

parseInt(null) results in NaN so that exclamation mark is definitely in the wrong here. (Remember to test after running window.localStorage.clear() in the console.)

@frostburn
Copy link
Member

GitHubActions seems to have something to say about your code style.

@frostburn
Copy link
Member

The commit message is too long. Use git commit --amend to reword it. (Also handy to avoid generating new commits so you avoid the rebases).

…of the top row of the interval matrix in Analysis view.
src/App.vue Outdated

if ("intervalMatrixIndexing" in storage) {
intervalMatrixIndexing.value = parseInt(
storage.getItem("intervalMatrixIndexing")!
Copy link
Member

Choose a reason for hiding this comment

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

Still doing naughty things and storing a NaN on first load.

Copy link
Member

Choose a reason for hiding this comment

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

This really should be parseInt(storage.getItem("intervalMatrixIndexing") ?? "0", 10)

@frostburn
Copy link
Member

Commits need squashing again.

@frostburn
Copy link
Member

Feel free to add your name on the About page.

@frostburn frostburn merged commit fe1717d into xenharmonic-devs:main Nov 29, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants