{"id":25649568,"url":"https://github.com/ruelalarcon/desmos_midi","last_synced_at":"2025-02-23T14:22:37.323Z","repository":{"id":278187535,"uuid":"933888343","full_name":"ruelalarcon/desmos_midi","owner":"ruelalarcon","description":"A Rust-based CLI tool for converting MIDI files into formulas for Desmos.","archived":false,"fork":false,"pushed_at":"2025-02-21T09:19:51.000Z","size":150,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-21T10:23:49.956Z","etag":null,"topics":["cli","desmos","midi","music","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruelalarcon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-16T22:45:08.000Z","updated_at":"2025-02-21T09:19:54.000Z","dependencies_parsed_at":"2025-02-21T10:23:51.839Z","dependency_job_id":null,"html_url":"https://github.com/ruelalarcon/desmos_midi","commit_stats":null,"previous_names":["ruelalarcon/desmos_music","ruelalarcon/desmos_midi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruelalarcon%2Fdesmos_midi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruelalarcon%2Fdesmos_midi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruelalarcon%2Fdesmos_midi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruelalarcon%2Fdesmos_midi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruelalarcon","download_url":"https://codeload.github.com/ruelalarcon/desmos_midi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240325171,"owners_count":19783626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","desmos","midi","music","rust"],"created_at":"2025-02-23T14:22:36.724Z","updated_at":"2025-02-23T14:22:37.247Z","avatar_url":"https://github.com/ruelalarcon.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Desmos MIDI Player\n\n\u003e A Rust-based CLI tool for converting MIDI files into formulas for Desmos. Complete with support for note velocity, tempo changes, and even custom soundfonts for different channels/instruments.\n\n## Installation\n\nTo use the MIDI Player, you must have [Rust](https://www.rust-lang.org/tools/install) installed on your system.\n\n### Prerequisites\n\n**Windows:**\n- No additional prerequisites\n\n**Linux/WSL (Ubuntu/Debian):**\n```bash\n# Install X11 development libraries\nsudo apt update\nsudo apt install libxcb1-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev\n```\n\n**Other Linux distributions:**\n- Equivalent X11 development packages for your package manager\n\n### Building\n\nClone this repository and navigate to the directory:\n\n```bash\ngit clone https://github.com/ruelalarcon/desmos_midi.git\ncd desmos_midi\n```\n\nThen build the project using the provided script:\n\n**Windows:**\n```bash\n./build.bat\n```\n\n**Linux/Mac:**\n```bash\n./build.sh\n```\n\u003e Note: You may need to run `chmod +x *.sh` first to make the scripts executable if they aren't by default.\n\nTo clean build artifacts at any time, you can use:\n```bash\n./clean.bat  # Windows\n./clean.sh   # Linux/Mac\n```\n\n## Usage\n\nNavigate to [this Desmos graph](https://www.desmos.com/calculator/dgkzdezlzf).\n\nOnce you have a MIDI file you wish to use, run the following command:\n\n**Basic Usage:**\n```bash\n./run.bat \u003cmidi_file\u003e  # Windows\n./run.sh \u003cmidi_file\u003e   # Linux/Mac\n```\n\u003e Note: From now on, we will use `.sh` for the rest of the examples, but if you are on Windows make sure to use the `.bat` versions instead.\n\n**Advanced Usage:**\n```bash\n./run.sh \u003cmidi_file\u003e -s \u003csoundfont1\u003e \u003csoundfont2\u003e ...  # Specify soundfonts for each channel\n./run.sh \u003cmidi_file\u003e -i                                # Show channel information\n```\n\n### Arguments\n- `\u003cmidi_file\u003e`: Path to the input MIDI file to convert\n- `-s, --soundfonts \u003cFILES\u003e`: Soundfont files to use for each channel (optional)\n- `-i, --info`: Show MIDI channel information and exit\n- `-c, --copy`: Copy output to clipboard instead of console\n\n### Soundfonts\nBy default:\n- Regular channels use `default.txt` soundfont\n- Drum channels (channel 10) are automatically ignored\n- To include drum sounds or use different soundfonts, use the `-s` option and specify a soundfont for each channel\n- Use `-` as a soundfont name to ignore that channel\n\n### Usage Examples\n\n1. Basic conversion with default settings (drums ignored):\n```bash\n./run.sh song.mid\n```\n\n2. View channel information:\n```bash\n./run.sh song.mid -i\n```\n\n3. Specify custom soundfonts:\n```bash\n./run.sh song.mid -s default.txt sine.txt - default.txt\n```\nThis will use:\n- `default.txt` for channel 1\n- `sine.txt` for channel 2\n- ignore channel 3\n- `default.txt` for channel 4\n\n4. Copy to clipboard instead of console output:\n```bash\n./run.sh song.mid -c\n```\n\nNow enable audio in Desmos through the button in the top left:\n![Enable audio](./assets/enable_audio.png)\n\n### Graph Controls\n\n- To play the song, hit the arrow button to the left of the `t -\u003e 0` formula.\n- To end the song, hit the arrow button to the left of the `t -\u003e ∞` formula.\n- You may also set the value of `t` manually to seek to a specific point in the song.\n- Open the \"Settings\" folder to adjust:\n  - `velocity`: Animation phase speed\n  - `scale`: Visual waveform amplitude\n  - `hertz`: Base frequency (default 440Hz)\n  - `detune`: The amount of detune applied to the secondary tone\n  - `volume`: Global volume control\n  - `transpose`: Global pitch shift in semitones\n\n## Technical Details\n\n### MIDI Processing\n\n1. **MIDI Parsing**:\n   - Uses the `midly` crate to parse MIDI files\n   - Extracts note events (Note On/Off) and timing information\n   - Handles tempo changes to ensure accurate timing\n   - Preserves note velocities (0-127) for dynamic volume control\n   - Properly tracks note durations for accurate playback\n\n2. **Timing Conversion**:\n   - Converts MIDI ticks to milliseconds using the formula:\n     ```\n     ms = (ticks * tempo) / (ticks_per_quarter * 1000)\n     ```\n   - Where:\n     - `ticks`: MIDI event time in ticks\n     - `tempo`: Microseconds per quarter note (default: 500000 = 120 BPM)\n     - `ticks_per_quarter`: MIDI file's time division (ticks per quarter note)\n\n3. **Note Processing**:\n   - Tracks active notes and their velocities at each timestamp\n   - Converts MIDI note numbers to relative positions from A (MIDI note 69 / 440 Hz)\n   - Each note is paired with its velocity value and duration\n   - Generates a Desmos piecewise function in the format:\n     ```\n     A=\\left\\{t\u003c1:\\left[0,100,0\\right],t\u003c2:\\left[2,85,0\\right],...\\right\\}\n     ```\n   - Where each note is represented by three values:\n     - Semitones relative to A4 (440Hz)\n     - Velocity (0-127)\n     - Soundfont index\n\n4. **Section Processing**:\n   - If a MIDI file is too long for Desmos to parse, the program will automatically split it into sections\n   - The sections are named `A_{1}`, `A_{2}`, etc.\n   - The main `A` formula selects the appropriate section based on time\n\n5. **Soundfont Processing**:\n   - Soundfonts are stored in the `soundfonts/` directory and are text files containing comma-separated floating point values representing harmonic weights (weights for each frequency in the harmonic series, which can be used to generate a static waveform)\n   - The `B` is a \"list of lists\" of harmonic weights, however, Desmos does not support nested lists so instead, the `C` value is the maximum size of the soundfont arrays (after padding) and we use that to index sublists in `B`\n\n## Dependencies\n\n- `midly`: MIDI file parsing\n- `clipboard`: System clipboard integration\n- `clap`: Command line argument parsing\n\n## Credits\n\n- [Desmos](https://www.desmos.com/) for the formula visualization\n- [Berrynote](https://www.youtube.com/@berrynote/videos) for the initial graph for playing notes on Desmos. [Berrynote's recent video](https://www.youtube.com/watch?v=g2Lp-gIa3es) was the inspiration and base for this project.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruelalarcon%2Fdesmos_midi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruelalarcon%2Fdesmos_midi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruelalarcon%2Fdesmos_midi/lists"}