From 5bb794bc8ad6a7530d22b5d77c37ef9c283a99b2 Mon Sep 17 00:00:00 2001 From: Denis Thiessen Date: Sat, 18 May 2024 12:28:32 +0200 Subject: [PATCH] feat: Add basic AudioHandler/Helpers --- src/core/audio/AudioHandler.jsx | 33 +++++++++++++++++++++++++++++++++ src/core/audio/ChordHelper.jsx | 26 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/core/audio/AudioHandler.jsx create mode 100644 src/core/audio/ChordHelper.jsx diff --git a/src/core/audio/AudioHandler.jsx b/src/core/audio/AudioHandler.jsx new file mode 100644 index 0000000..1f4534e --- /dev/null +++ b/src/core/audio/AudioHandler.jsx @@ -0,0 +1,33 @@ +import {Component} from 'react'; +import * as Tone from "tone"; + +export default class AudioHandler extends Component { + + playTabEarconSonification() { + + } + + playTabModelSonification() { + + } + + playDetailEarconSonification() { + + } + + playDetailModelSonification() { + + } + + setRotation(angle) { + Tone.Listener.forwardX.value = Math.sin(angle); + Tone.Listener.forwardY.value = 0; + Tone.Listener.forwardZ.value = -Math.cos(angle); + } + + setRotationRamp(panner, angle, rampTime) { + panner.positionX.rampTo(Math.sin(angle), rampTime); + panner.positionY.rampTo(0, rampTime); + panner.positionZ.rampTo(-Math.cos(angle), rampTime); + } +} \ No newline at end of file diff --git a/src/core/audio/ChordHelper.jsx b/src/core/audio/ChordHelper.jsx new file mode 100644 index 0000000..2ae35be --- /dev/null +++ b/src/core/audio/ChordHelper.jsx @@ -0,0 +1,26 @@ +import * as Tone from "tone"; + +export function buildChord(notes, octave) { + return notes.map(note => {return (note + octave);}) +} + +export function buildNote(note, octave) { + return (note + octave); +} + +export function generateChord(rootNote, chordType) { + // Define intervals for different chord types + const chordIntervals = { + 'major': [0, 4, 7], + 'minor': [0, 3, 7], + '7th': [0, 4, 7, 10], + 'diminished': [0, 3, 6], + 'augmented': [0, 4, 8], + 'sus2': [0, 2, 7], + 'sus4': [0, 5, 7] + }; + + const intervals = chordIntervals[chordType]; + + return Tone.Frequency(rootNote).harmonize(intervals); +} \ No newline at end of file