Skip to content

Commit

Permalink
adding preferences for speed control - forgot to add it, oops
Browse files Browse the repository at this point in the history
  • Loading branch information
neontomo committed Feb 23, 2025
1 parent 9790600 commit 9ca955f
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 67 deletions.
58 changes: 13 additions & 45 deletions extensions/slowed-reverb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
"description": "Turn any song into a Slowed + Reverb version",
"icon": "extension_icon.png",
"author": "tomo_myrman",
"categories": [
"Fun",
"Media"
],
"license": "MIT",
"scripts": {
"ray": "ray",
"build": "ray build -e dist -o ./dist",
"dev": "ray develop",
"fix-lint": "ray lint --fix",
"lint": "ray lint",
"publish": "npx @raycast/api@latest publish"
},
"commands": [
{
"name": "generate-slowed",
Expand Down Expand Up @@ -54,22 +57,6 @@
"default": "0.8",
"required": true,
"data": [
{
"title": "0.1",
"value": "0.1"
},
{
"title": "0.2",
"value": "0.2"
},
{
"title": "0.3",
"value": "0.3"
},
{
"title": "0.4",
"value": "0.4"
},
{
"title": "0.5",
"value": "0.5"
Expand Down Expand Up @@ -119,26 +106,15 @@
{
"title": "1.5",
"value": "1.5"
},
{
"title": "1.6",
"value": "1.6"
},
{
"title": "1.7",
"value": "1.7"
},
{
"title": "1.8",
"value": "1.8"
},
{
"title": "1.9",
"value": "1.9"
}
]
}
],
"categories": [
"Fun",
"Media"
],
"license": "MIT",
"dependencies": {
"@raycast/api": "^1.92.1",
"@raycast/utils": "^1.17.0",
Expand All @@ -151,13 +127,5 @@
"eslint": "^8.57.0",
"prettier": "^3.3.3",
"typescript": "^5.4.5"
},
"scripts": {
"ray": "ray",
"build": "ray build",
"dev": "ray develop",
"fix-lint": "ray lint --fix",
"lint": "ray lint",
"publish": "npx @raycast/api@latest publish"
}
}
8 changes: 7 additions & 1 deletion extensions/slowed-reverb/src/generate-nightcore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Init from './setup/init'
import { convertersUtils } from './utils/converters.utils'
import { errorUtils } from './utils/errors.utils'

const Nightcore = async () => {
Init('nightcore')
const converterName = 'nightcore'
const { successToast } = convertersUtils.converters[converterName]

await Init(converterName)
await errorUtils.showToastSuccess({ title: successToast.title })
}

export default Nightcore
8 changes: 7 additions & 1 deletion extensions/slowed-reverb/src/generate-reverb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Init from './setup/init'
import { convertersUtils } from './utils/converters.utils'
import { errorUtils } from './utils/errors.utils'

const Reverb = async () => {
Init('reverb')
const converterName = 'reverb'
const { successToast } = convertersUtils.converters[converterName]

await Init(converterName)
await errorUtils.showToastSuccess({ title: successToast.title })
}

export default Reverb
8 changes: 7 additions & 1 deletion extensions/slowed-reverb/src/generate-slowed-reverb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Init from './setup/init'
import { convertersUtils } from './utils/converters.utils'
import { errorUtils } from './utils/errors.utils'

const SlowedAndReverb = async () => {
Init('slowedAndReverb')
const converterName = 'slowedAndReverb'
const { successToast } = convertersUtils.converters[converterName]

await Init(converterName)
await errorUtils.showToastSuccess({ title: successToast.title })
}

export default SlowedAndReverb
8 changes: 7 additions & 1 deletion extensions/slowed-reverb/src/generate-slowed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Init from './setup/init'
import { convertersUtils } from './utils/converters.utils'
import { errorUtils } from './utils/errors.utils'

const Slowed = async () => {
Init('slowed')
const converterName = 'slowed'
const { successToast } = convertersUtils.converters[converterName]

await Init(converterName)
await errorUtils.showToastSuccess({ title: successToast.title })
}

export default Slowed
4 changes: 1 addition & 3 deletions extensions/slowed-reverb/src/setup/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Init = async (currentConverter: keyof Converters) => {
const { converters, converter } = convertersUtils
const { showToastError, showToastSuccess, throwError, CONSTANTS } = errorUtils
const { getSelectedFilePaths } = fileUtils
const { command, fileNameSuffix, initialToast, successToast } = converters[currentConverter]
const { command, fileNameSuffix, initialToast } = converters[currentConverter]
const { isSoxInstalled } = soxUtils

try {
Expand All @@ -16,8 +16,6 @@ const Init = async (currentConverter: keyof Converters) => {

const files = await getSelectedFilePaths()
files.forEach((inputPath) => converter(inputPath, command, fileNameSuffix))

await showToastSuccess({ title: successToast.title })
} catch (error) {
await showToastError(error)
}
Expand Down
31 changes: 22 additions & 9 deletions extensions/slowed-reverb/src/utils/converters.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ToastType } from './errors.utils'
import { fileUtils } from './file.utils'
import { preferenceUtils } from './preference.utils'
import { soxUtils } from './sox.utils'

export type Converters = {
Expand All @@ -10,16 +11,21 @@ export type Converters = {
}

export type Converter = {
command: (inputPath: string, outputPath: string) => string
command: (args: {
inputPath: string
outputPath: string
slowedSpeed?: string
nightcoreSpeed?: string
}) => string
fileNameSuffix: 'slowed' | 'reverb' | 'slowed-reverb' | 'nightcore'
initialToast: ToastType
successToast: ToastType
}

const converters: Converters = {
slowed: {
command: (inputPath: string, outputPath: string) =>
`-N -V1 --ignore-length -G "${inputPath}" -C 320 -r 44100 -b 24 -c 2 "${outputPath}" speed 0.8`,
command: ({ inputPath, outputPath, slowedSpeed }) =>
`-N -V1 --ignore-length -G "${inputPath}" -C 320 -r 44100 -b 24 -c 2 "${outputPath}" speed ${slowedSpeed}`,
fileNameSuffix: 'slowed',
initialToast: {
title: 'slowing down without reverb',
Expand All @@ -31,7 +37,7 @@ const converters: Converters = {
}
},
reverb: {
command: (inputPath: string, outputPath: string) =>
command: ({ inputPath, outputPath }) =>
`-N -V1 --ignore-length -G "${inputPath}" -C 320 -r 44100 -b 24 -c 2 "${outputPath}" reverb 50 50 100 100 20 0`,
fileNameSuffix: 'reverb',
initialToast: {
Expand All @@ -44,8 +50,8 @@ const converters: Converters = {
}
},
slowedAndReverb: {
command: (inputPath: string, outputPath: string) =>
`-N -V1 --ignore-length -G "${inputPath}" -C 320 -r 44100 -b 24 -c 2 "${outputPath}" speed 0.8 reverb 50 50 100 100 20 0`,
command: ({ inputPath, outputPath, slowedSpeed }) =>
`-N -V1 --ignore-length -G "${inputPath}" -C 320 -r 44100 -b 24 -c 2 "${outputPath}" speed ${slowedSpeed} reverb 50 50 100 100 20 0`,
fileNameSuffix: 'slowed-reverb',
initialToast: {
title: 'slowing down + adding reverb',
Expand All @@ -57,8 +63,8 @@ const converters: Converters = {
}
},
nightcore: {
command: (inputPath: string, outputPath: string) =>
`-N -V1 --ignore-length -G "${inputPath}" -C 320 -r 44100 -b 24 -c 2 "${outputPath}" speed 1.2`,
command: ({ inputPath, outputPath, nightcoreSpeed }) =>
`-N -V1 --ignore-length -G "${inputPath}" -C 320 -r 44100 -b 24 -c 2 "${outputPath}" speed ${nightcoreSpeed}`,
fileNameSuffix: 'nightcore',
initialToast: {
title: 'converting to nightcore',
Expand All @@ -78,9 +84,16 @@ const converter = async (
) => {
const { getOutputPath } = fileUtils
const { executeSoxCommand } = soxUtils
const { getAllDefaultSpeeds } = preferenceUtils
const speeds = getAllDefaultSpeeds()

const outputPath = getOutputPath(inputPath, fileNameSuffix)
const command = converter(inputPath, outputPath)
const command = converter({
inputPath,
outputPath,
slowedSpeed: speeds.slowed,
nightcoreSpeed: speeds.nightcore
})
executeSoxCommand(command)
}

Expand Down
3 changes: 2 additions & 1 deletion extensions/slowed-reverb/src/utils/errors.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type ToastType = {

const CONSTANTS = {
noSoxInstalled: 'sox is not installed. please install it via homebrew',
noSongsSelected: 'no songs selected'
noSongsSelected: 'no songs selected',
noPreferenceKey: 'preference setting not found'
}

const throwError = (message: string) => {
Expand Down
27 changes: 27 additions & 0 deletions extensions/slowed-reverb/src/utils/preference.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getPreferenceValues } from '@raycast/api'
import { errorUtils } from './errors.utils'

const getPreference = (key: keyof Preferences): string => {
const { throwError, CONSTANTS } = errorUtils
try {
return getPreferenceValues<Preferences>()[key]
} catch (error) {
throwError(CONSTANTS.noPreferenceKey)
return ''
}
}

const getDefaultSlowedSpeed = () => getPreference('defaultSlowedSpeed') || '0.8'
const getDefaultNightcoreSpeed = () => getPreference('defaultNightcoreSpeed') || '1.2'

const getAllDefaultSpeeds = () => ({
slowed: getDefaultSlowedSpeed(),
nightcore: getDefaultNightcoreSpeed()
})

export const preferenceUtils = {
getPreference,
getDefaultSlowedSpeed,
getDefaultNightcoreSpeed,
getAllDefaultSpeeds
}
7 changes: 2 additions & 5 deletions extensions/slowed-reverb/src/utils/sox.utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { getPreferenceValues } from '@raycast/api'
import { execSync } from 'child_process'

export function getPreference(key: keyof Preferences): string {
return getPreferenceValues<Preferences>()[key]
}
import { preferenceUtils } from './preference.utils'

const getSoxPath = () => {
const { getPreference } = preferenceUtils
const defaultSoxPath = getPreference('customSoxPath')
const commandFolderPath = execSync(`
locations=(
Expand Down

0 comments on commit 9ca955f

Please sign in to comment.