Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": ["next/core-web-vitals", "next/typescript", "prettier"],
"parserOptions": {
"project": ["tsconfig.json"]
},
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
Expand All @@ -8,6 +11,7 @@
"varsIgnorePattern": "^_"
}
],
"@typescript-eslint/require-array-sort-compare": "error",
"@next/next/no-img-element": "off"
}
}
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
checks:
name: Lint and Test
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'

- name: Install dependencies
run: |
corepack enable
yarn install --immutable

- name: Type check
run: yarn tsc

- name: Check Lint & Format
run: yarn lint:check

- name: Run tests
run: yarn test

- name: Run build
run: yarn build
48 changes: 48 additions & 0 deletions .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Version Check

on:
pull_request:
branches: ['main']

jobs:
version-check:
name: Check Version Bump
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read

steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Get PR version
id: pr_version
run: |
PR_VERSION=$(node -p "require('./package.json').version")
echo "version=$PR_VERSION" >> $GITHUB_OUTPUT

- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
path: main

- name: Get main version
id: main_version
run: |
MAIN_VERSION=$(node -p "require('./main/package.json').version")
echo "version=$MAIN_VERSION" >> $GITHUB_OUTPUT

- name: Compare versions
run: |
PR_VERSION="${{ steps.pr_version.outputs.version }}"
MAIN_VERSION="${{ steps.main_version.outputs.version }}"

if ! npx semver --range ">$MAIN_VERSION" "$PR_VERSION"; then
echo "Error: Version in PR ($PR_VERSION) is not higher than version in main ($MAIN_VERSION)"
exit 1
fi
echo "Version check passed: $PR_VERSION > $MAIN_VERSION"
6 changes: 4 additions & 2 deletions app/components/instrument-stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ export const getVelocityValues = (
// To do this, it tries every cluster number until the mean difference improvement
// is less than the threshold. Then groups that are too close together are merged.
// The resulting number of groups is the target number for a final k-means clustering.
return autoCluster({ data }).centers.toSorted()
return autoCluster({ data }).centers.toSorted((a, b) => a - b)
}

return kMeansClustering(data, targetNumberOfClusters).centers.toSorted()
return kMeansClustering(data, targetNumberOfClusters).centers.toSorted(
(a, b) => a - b,
)
}

export type InstrumentStageProps = {
Expand Down
31 changes: 18 additions & 13 deletions app/components/select-stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export type SelectStageProps = {
setSong: Dispatch<Song | undefined>
}

const useDragAndDrop = (onFile: (file: ArrayBuffer, fileName: string) => Promise<void>) => {
const useDragAndDrop = (
onFile: (file: ArrayBuffer, fileName: string) => Promise<void>,
) => {
const [isDragging, setIsDragging] = useState(false)

useEffect(() => {
Expand Down Expand Up @@ -89,21 +91,24 @@ export const SelectStage = ({ setSong }: SelectStageProps) => {
const postHog = usePostHog()
const [loadingMessage, setLoadingMessage] = useState('')

const processFile = useCallback(async (file: ArrayBuffer, fileName: string) => {
postHog.capture('Selected midi file', {
'File Name': fileName,
})
setSong(undefined)
const processFile = useCallback(
async (file: ArrayBuffer, fileName: string) => {
postHog.capture('Selected midi file', {
'File Name': fileName,
})
setSong(undefined)

requestAnimationFrame(() => {
setLoadingMessage('Loading file...')
requestAnimationFrame(() => {
const song = new Midi(file.slice(0))
setSong(midiToSong(song, fileName))
setLoadingMessage('')
setLoadingMessage('Loading file...')
requestAnimationFrame(() => {
const song = new Midi(file.slice(0))
setSong(midiToSong(song, fileName))
setLoadingMessage('')
})
})
})
}, [postHog, setSong])
},
[postHog, setSong],
)

const { openFilePicker } = useFilePicker({
accept: ['audio/midi', 'audio/x-midi'],
Expand Down
156 changes: 108 additions & 48 deletions app/lib/__snapshots__/kmeans.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading