Skip to content

Commit

Permalink
statemerge complete
Browse files Browse the repository at this point in the history
  • Loading branch information
jgentes committed May 21, 2024
1 parent 0cc5bf2 commit bcb12ed
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 234 deletions.
16 changes: 8 additions & 8 deletions app/api/handlers/audioEvents.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
type Stem,
type Track,
db,
updateTrack,
updateTrack
} from '~/api/handlers/dbHandlers'
import {
type TrackState,
audioState,
mixState,
uiState,
uiState
} from '~/api/models/appState.client'
import { convertToSecs } from '~/utils/tableOps'

Expand All @@ -35,7 +35,7 @@ const audioEvents = {
initAudioContext: ({
trackId,
stem,
media,
media
}: {
trackId: Track['id']
stem?: Stem
Expand Down Expand Up @@ -258,7 +258,7 @@ const audioEvents = {

audioEvents.initAudioContext({
trackId,
media: waveform.getMediaElement(),
media: waveform.getMediaElement()
})

waveform.play()
Expand All @@ -274,7 +274,7 @@ const audioEvents = {
audioEvents.initAudioContext({
trackId,
stem: stem as Stem,
media: stemWaveform.getMediaElement(),
media: stemWaveform.getMediaElement()
})
stemWaveform.play()
}
Expand Down Expand Up @@ -412,7 +412,7 @@ const audioEvents = {
// [left, right] @ 0% = [1, 0] 50% = [1, 1] 100% = [0, 1]
const volumes = [
Math.min(1, 1 + Math.cos(sliderPercent * Math.PI)),
Math.min(1, 1 + Math.cos((1 - sliderPercent) * Math.PI)),
Math.min(1, 1 + Math.cos((1 - sliderPercent) * Math.PI))
]

if (mixState.tracks.length) {
Expand All @@ -427,7 +427,7 @@ const audioEvents = {
volume: trackVol = 1,
stems,
gainNode,
stemState,
stemState
} = audioState[trackId]

// if we have a stemType, this is a stem crossfader
Expand Down Expand Up @@ -604,7 +604,7 @@ const audioEvents = {

// Remove from stemsAnalyzing
uiState.stemsAnalyzing.delete(trackId)
},
}
}

export { audioEvents }
14 changes: 7 additions & 7 deletions app/api/handlers/audioHandlers.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
audioState,
mixState,
uiState,
userState,
userState
} from '~/api/models/appState.client'
import { errorHandler } from '~/utils/notifications'

Expand Down Expand Up @@ -52,7 +52,7 @@ async function getTracksRecursively(
size,
type,
fileHandle: fileOrDirectoryHandle,
dirHandle,
dirHandle
})
} else if (fileOrDirectoryHandle.kind === 'directory') {
for await (const handle of fileOrDirectoryHandle.values()) {
Expand Down Expand Up @@ -93,7 +93,7 @@ async function getTracksRecursively(
onCancel: () => {
uiState.modal.openState = false
uiState.processing = false
},
}
}
return []
}
Expand All @@ -105,7 +105,7 @@ const analyzeTracks = async (tracks: Track[]): Promise<Track[]> => {
// Set analyzing state now to avoid tracks appearing with 'analyze' button
uiState.analyzing = new Set([
...uiState.analyzing,
...tracks.map(track => track.id),
...tracks.map(track => track.id)
])

// Return array of updated tracks
Expand Down Expand Up @@ -135,7 +135,7 @@ const analyzeTracks = async (tracks: Track[]): Promise<Track[]> => {
bpm: normalizedBpm,
offset,
sampleRate,
...rest,
...rest
}

const [trackWithId] = await putTracks([updatedTrack])
Expand Down Expand Up @@ -192,7 +192,7 @@ const getAudioDetails = async (
offset,
bpm,
duration,
sampleRate,
sampleRate
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ const calcMarkers = async (trackId: Track['id']): Promise<void> => {
start: time,
end: time,
color: 'rgba(4, 146, 247, 0.757)',
drag: false,
drag: false
})
}
}
Expand Down
32 changes: 16 additions & 16 deletions app/api/handlers/dbHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { useLiveQuery } from 'dexie-react-hooks'
import { audioEvents } from '~/api/handlers/audioEvents.client'
import { getPermission } from '~/api/handlers/fileHandlers'
import {
__EFFECTS as EFFECTS,
type __Effect as Effect,
type __Mix as Mix,
type __MixSet as MixSet,
type __Mixpoint as Mixpoint,
__STEMS as STEMS,
type __Stem as Stem,
type __Track as Track,
type __TrackCache as TrackCache,
__db as db,
} from '~/api/models/__dbSchema'
EFFECTS,
type Effect,
type Mix,
type MixSet,
type Mixpoint,
STEMS,
type Stem,
type Track,
type TrackCache,
db
} from '~/api/models/appModels'
import { audioState, mixState } from '~/api/models/appState.client'
import { errorHandler } from '~/utils/notifications'

Expand All @@ -22,7 +22,7 @@ const CACHE_LIMIT = 25
const storeTrackCache = async ({
id,
file,
stems,
stems
}: {
id: TrackCache['id']
file?: TrackCache['file']
Expand Down Expand Up @@ -83,7 +83,7 @@ const putTracks = async (tracks: TrackIdOptional[]): Promise<Track[]> => {
}

const updatedTracks = await db.tracks.bulkPut(bulkTracks as Track[], {
allKeys: true,
allKeys: true
})
return (await db.tracks.bulkGet(updatedTracks)) as Track[]
}
Expand Down Expand Up @@ -137,7 +137,7 @@ const putMixpoint = async (

return await db.mixpoints.put({
name,
effects,
effects
})
}

Expand All @@ -148,7 +148,7 @@ const putMixpoint = async (

const newMixpoint = {
...currentMixpoint,
...{ name: name || currentMixpoint.name, effects: newEffects },
...{ name: name || currentMixpoint.name, effects: newEffects }
}

await db.mixpoints.put(newMixpoint, mixpointId)
Expand Down Expand Up @@ -195,5 +195,5 @@ export {
removeMix,
addToMix,
getTrackName,
storeTrackCache,
storeTrackCache
}
12 changes: 6 additions & 6 deletions app/api/handlers/fileHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
type TrackCache,
addToMix,
db,
storeTrackCache,
storeTrackCache
} from '~/api/handlers/dbHandlers'
import type { StemState } from '~/api/models/appModels'
import {
type StemState,
audioState,
mixState,
uiState,
userState,
userState
} from '~/api/models/appState.client'
import { errorHandler } from '~/utils/notifications'
import { processTracks } from './audioHandlers.client'
Expand All @@ -33,7 +33,7 @@ function showOpenFilePickerPolyfill(options: OpenFilePickerOptions) {
getFile: async () =>
new Promise(resolve => {
resolve(file)
}),
})
}
})
)
Expand Down Expand Up @@ -159,7 +159,7 @@ const getStemsDirHandle = async (): Promise<
const newStemsDirHandle = await window.showDirectoryPicker({
startIn: stemsDirHandle,
id: 'stemsDir',
mode: 'readwrite',
mode: 'readwrite'
})

if (
Expand Down Expand Up @@ -190,7 +190,7 @@ const validateTrackStemAccess = async (
// do we have access to the stem dir?
try {
const stemDirAccess = await stemsDirHandle.queryPermission({
mode: 'readwrite',
mode: 'readwrite'
})
if (stemDirAccess !== 'granted') return 'grantStemDirAccess'
} catch (e) {
Expand Down
14 changes: 7 additions & 7 deletions app/api/handlers/stemHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type Stem,
type Track,
db,
storeTrackCache,
storeTrackCache
} from '~/api/handlers/dbHandlers'
import { getStemsDirHandle } from '~/api/handlers/fileHandlers'
import { audioState } from '~/api/models/appState.client'
Expand Down Expand Up @@ -51,7 +51,7 @@ const stemAudio = async (trackId: Track['id']) => {
try {
await fetch(ENDPOINT_URL, {
method: 'PUT',
body: formData,
body: formData
})
} catch (e) {
return handleErr('Error uploading file for stem processing')
Expand All @@ -69,7 +69,7 @@ const stemAudio = async (trackId: Track['id']) => {
return new Promise((resolve, reject) => {
const waitForStems = async (): Promise<void> => {
const res = await fetch(ENDPOINT_URL, {
method: 'HEAD',
method: 'HEAD'
})

if (res.status === 202) {
Expand All @@ -87,7 +87,7 @@ const stemAudio = async (trackId: Track['id']) => {
return {
name: `${FILENAME} - ${stem}.mp3`,
type: stem,
file: await res.blob(),
file: await res.blob()
}
throw new Error(await res?.text())
})
Expand Down Expand Up @@ -118,15 +118,15 @@ const stemAudio = async (trackId: Track['id']) => {
let stemsDirHandle: FileSystemDirectoryHandle
try {
stemsDirHandle = await dirHandle.getDirectoryHandle(`${FILENAME} - stems`, {
create: true,
create: true
})
} catch (e) {
throw errorHandler('Error creating directory for stems.')
}

for (const { name, type, file } of stems) {
const stemFile = await stemsDirHandle.getFileHandle(name, {
create: true,
create: true
})

const writable = await stemFile.createWritable()
Expand All @@ -140,7 +140,7 @@ const stemAudio = async (trackId: Track['id']) => {
// store stem in cache
await storeTrackCache({
id: trackId,
stems: { [type]: { file } },
stems: { [type]: { file } }
})
}
// give a couple of seconds before trying to render the stem waveform
Expand Down
Loading

0 comments on commit bcb12ed

Please sign in to comment.