Skip to content

Commit

Permalink
Feature: synth preset customization (#14)
Browse files Browse the repository at this point in the history
* refactor: move sequenceOption type and defaultValue

* add config feature

* refactor ui

* fix

* feat: save synth config

* update app version
  • Loading branch information
r4ai authored Apr 1, 2023
1 parent 3451c08 commit b9942c5
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins:
- "prettier-plugin-organize-imports"
- "prettier-plugin-tailwindcss"
pluginSearchDirs:
- "."
- "./src/"
overrides:
- files: "*.svelte"
options:
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"vs-code-prettier-eslint.prettierLast": false, // set as "true" to run 'prettier' last not first
"prettier.documentSelectors": ["**/*.svelte"],
"prettier.configPath": ".prettierrc.yaml",
"prettier.ignorePath": ".prettierignore",
"[svelte]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand All @@ -35,9 +36,11 @@
"cSpell.words": [
"ACRN",
"APPCONFIG",
"fatsine",
"headphonejames",
"imgs",
"Neuromodulation",
"testid",
"Unsubscriber"
],
"markdownlint.config": {
Expand Down
6 changes: 4 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "tinnitus-reducer-ACRN",
"version": "0.1.3"
"version": "0.2.0"
},
"tauri": {
"allowlist": {
Expand Down Expand Up @@ -68,7 +68,9 @@
"resizable": true,
"title": "tinnitus reducer ACRN",
"width": 800,
"height": 600
"minWidth": 450,
"height": 600,
"minHeight": 200
}
]
}
Expand Down
8 changes: 7 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
theme,
pan,
clientWidth,
loopRepeat,
restLength,
duration,
} from "./lib/stores";
import FrequencyController from "./lib/FrequencyController.svelte";
import PlayController from "./lib/PlayController.svelte";
Expand All @@ -27,7 +30,7 @@
import Navbar from "./lib/nav/Navbar.svelte";
import ConfigPanel from "./lib/config_panel/ConfigPanel.svelte";
import { isTauri } from "./lib/utils";
import type { SettingsScheme } from "./lib/constants";
import type { SettingsScheme } from "./lib/stores";
let unsubscribeStores: Unsubscriber[] | undefined = undefined;
let unsubscribeLazySave: Unsubscriber | undefined = undefined;
Expand Down Expand Up @@ -68,6 +71,9 @@
$bpm = [settings.bpm];
$pan = [settings.pan];
$theme = settings.theme;
$loopRepeat = [settings.loopRepeat];
$restLength = [settings.restLength];
$duration = [settings.duration];
}
// * Setup Tone.js
Expand Down
50 changes: 28 additions & 22 deletions src/lib/Sequence.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@
return synth;
}
export type SequenceOption = {
loopRepeat: number;
restLength: number;
duration: Tone.Unit.Time;
};
export const defaultSequenceOption: SequenceOption = {
loopRepeat: 3,
restLength: 2,
duration: "4n",
};
/**
* Create a sequence of frequencies and start it.
* TODO: Refactor the code inside the Tone.Sequence
Expand All @@ -105,7 +93,7 @@
export function createSequence(
synth: PolySynth | Synth,
frequencies: number[],
{ loopRepeat, restLength, duration } = defaultSequenceOption
{ loopRepeat, restLength, duration } = DEFAULT_SEQUENCE_OPTION
): Sequence {
let currentFrequencies = shuffledFrequencies(frequencies);
Expand Down Expand Up @@ -139,7 +127,7 @@
oldSeq: Sequence | undefined,
synth: PolySynth | Synth | undefined,
frequencies: number[],
option = defaultSequenceOption
option = DEFAULT_SEQUENCE_OPTION
): Sequence | undefined {
if (synth) {
oldSeq?.dispose();
Expand All @@ -155,13 +143,27 @@
<script lang="ts">
import { onDestroy, onMount } from "svelte";
import { derived } from "svelte/store";
import { derived, type Readable } from "svelte/store";
import type { Panner, PolySynth, Sequence, Synth, SynthOptions } from "tone";
import * as Tone from "tone";
import { SHEET_RANDOM_FREQUENCY, SHEET_REST } from "./constants";
import {
DEFAULT_SEQUENCE_OPTION,
SHEET_RANDOM_FREQUENCY,
SHEET_REST,
} from "./constants";
import { createPanner } from "./Oscillator.svelte";
import { isPlaying, mode, frequency, bpm, pan } from "./stores";
import {
isPlaying,
mode,
frequency,
bpm,
pan,
loopRepeat,
restLength,
duration,
type SequenceOption,
} from "./stores";
let synth: PolySynth | undefined = undefined;
let panner: Panner | undefined = undefined;
Expand All @@ -170,6 +172,14 @@
const frequencies = derived(frequency, $frequency =>
generateFrequencies($frequency[0])
);
const sequenceOption: Readable<SequenceOption> = derived(
[loopRepeat, restLength, duration],
([$loopRepeat, $restLength, $duration]) => ({
loopRepeat: $loopRepeat[0],
restLength: $restLength[0],
duration: $duration[0],
})
);
onMount(() => {
panner = createPanner();
Expand All @@ -187,11 +197,7 @@
// * Generate sequence of frequencies
$: {
if ($isPlaying) {
seq = updatedSequence(seq, synth, $frequencies, {
loopRepeat: 3,
restLength: 2 * 4,
duration: "4n",
});
seq = updatedSequence(seq, synth, $frequencies, $sequenceOption);
}
}
Expand Down
Loading

0 comments on commit b9942c5

Please sign in to comment.