danigb / samples

Repository to audio samples served from github pages
https://danigb.github.io/samples/
8 stars 2 forks source link

sfz2json bugs #2

Closed kmturley closed 7 months ago

kmturley commented 7 months ago

Hello, When using the sfz2json tool I found that issues with parsing such as:

1) Expects a top-level header It's possible to have an sfz file such as:

<region>
sample=piano.wav

which doesn't parse any values, I presume because it's missing global or groups.

2) Does not parse inline comments

<group>
lovel=64 // enter stuff here if you want to apply it to all regions
hivel=127

<region>
sample=Trumpet_C4_v2.wav

Returns:

{
  "meta": {},
  "global": {},
  "groups": [
    {
      "regions": [],
      "lovel": "64 // enter stuff here if you want to apply it to all regions",
      "hivel": 127
    }
  ]
}

There are lots of examples here you can use to test parsing code works correctly: https://github.com/sfz/tests

I have a few scripts which might be useful for testing: https://github.com/kmturley/sfz-tests/blob/feature/xml-and-json-compact/sfz-to-xml.sh https://github.com/kmturley/sfz-tests/blob/feature/xml-and-json-compact/xml-to-json.sh https://github.com/kmturley/sfz-tests/blob/feature/xml-and-json-compact/json-to-yaml.sh

I have written a JavaScript parser here which successfully parses all those files: https://github.com/kmturley/sfz-tools-core/blob/main/src/parse.ts#L116

However my parser uses non-compact json as I had issues with ordering of elements in compact json: https://www.npmjs.com/package/xml-js#compact-vs-non-compact

I made a command line tool which can be used to convert sfz to other formats and also convert the audio files: https://github.com/kmturley/sfz-tools-cli

danigb commented 7 months ago

Hi 👋

Awesome work! Your sfz-tools-core project looks great! In fact this repository is deprecated (soon to be archived) and will be replaced with https://github.com/smpldsnds

Anyway, I need a sfz parser for another project: https://github.com/danigb/smplr Have you consider to extract just the parser to another npm package? (I want to keep the dependencies to the bare minimum)

kmturley commented 7 months ago

Parser bugs

Ok no problem for this repo, maybe add deprecated to the README?

My sfz parser code

I really want don't want to have the parsing code in another package, as It creates more maintenance for me, and the tests are all setup for the parser.

I agree there is some bloat with the package as it is. I am using essentia.js for detecting audio samples and it is putting a load of runtime code into the package. There is also server-side and client-side mixed together, so if you import the wrong file it will break. Alot of what i've done so far is a prototype, but it is maturing and becoming more robust and reusable over time.

Some options:

1) Import only the methods you need directly (and it shouldn't import any other code or cause errors)

import { parseHeaders, parseSfz } from '@sfz-tools/core/dist/parse';

2) Make a copy of the methods you need They are mostly all standalone methods, would be fairly easy to make your own package or parser file. https://github.com/kmturley/sfz-tools-core/blob/main/src/parse.ts#L116 My code is licensed as CC-0 so you are free to do what you want with it. Maybe you can improve it :)

My sfz web player

You can see it working in my sfz web player prototype: https://github.com/kmturley/sfz-web-player/blob/main/src/components/Audio.ts#L8

It's still work in progress: https://kmturley.github.io/sfz-web-player I haven't implemented any of the audio engine/effects yet.

Sfz instrument repos

I see you have json files in your https://github.com/smpldsnds instrument repos. How are those generated?

I have a separate project where i'm doing a similar thing. Here is an example: https://github.com/studiorack/splendid-grand-piano

The repo has a plugins.json file: https://github.com/studiorack/splendid-grand-piano/blob/master/plugins.json An a Github action deploys a release automatically: https://github.com/studiorack/splendid-grand-piano/releases/tag/v1.0.0 Then I have a registry which scan GitHub for a special topic on the repo tag: https://github.com/studiorack/studiorack-registry Which aggregates all plugins into a master registry: https://studiorack.github.io/studiorack-registry/ Which can be used to power a website, command-line and app.

and I have a separate compact branch for each isntrument with the web version of sfz, json and ogg files: https://github.com/studiorack/splendid-grand-piano/tree/compact

All this is free open-source too, if you wanted to hook into something similar for smplr?