### Install PianoPlayer Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Install the PianoPlayer library using pip. This is the basic installation command. ```bash pip install pianoplayer ``` -------------------------------- ### Install and Run PianoPlayer Web API Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/README.md Install the necessary package and run the web API server locally. Access the API via the specified local address. ```bash pip install "pianoplayer[web]" uvicorn webapi.app:app --host 127.0.0.1 --port 8000 ``` -------------------------------- ### Install PianoPlayer with Optional Extras Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Install PianoPlayer with optional extras for specific functionalities like 3D rendering, MIDI support, or playback. ```bash pip install "pianoplayer[visual]" # 3D rendering with vedo ``` ```bash pip install "pianoplayer[midi]" # MIDI input support ``` ```bash pip install "pianoplayer[sound]" # enable playback ``` ```bash pip install "pianoplayer[all]" # all optional extras ``` -------------------------------- ### Upgrade Pip and Install PianoPlayer on Windows Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Upgrade pip and install PianoPlayer using Command Prompt on Windows. Ensure Python is added to PATH during installation. ```bash python -m pip install --upgrade pip pip install pianoplayer pianoplayer --help ``` -------------------------------- ### Upgrade Pip and Install PianoPlayer on macOS/Linux Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Upgrade pip and install PianoPlayer using the terminal on macOS or Linux. ```bash python3 -m pip install --upgrade pip pip install pianoplayer pianoplayer --help ``` -------------------------------- ### Check PianoPlayer Help on Windows with Anaconda Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Verify the PianoPlayer installation by checking its help command within an Anaconda Prompt on Windows. ```bash pianoplayer --help ``` -------------------------------- ### Build Standalone Executable Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Build a standalone executable for PianoPlayer without 3D visualization using PyInstaller. Ensure the build extra is installed first. ```bash pip install "pianoplayer[build]" python scripts/build_standalone.py ``` -------------------------------- ### GET /health Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/README.md Checks the health status of the PianoPlayer API. ```APIDOC ## GET /health ### Description Checks the health status of the PianoPlayer API. ### Method GET ### Endpoint /health ### Response #### Success Response (200) - `status` (string) - Indicates the API status, expected to be "ok". ``` -------------------------------- ### Full CLI Help and Options Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Displays all available command-line options for PianoPlayer, including help, GUI launch, output file, measure selection, routing, verbosity, and visualization settings. ```bash pianoplayer [-h] [--gui] [-o] [-n] [-s] [-d] [-rpart] [-lpart] [--rstaff] [--lstaff] [--auto-routing | --manual-routing] [--quiet] [-m] [-b] [--colorize-hands] [--colorize-by-cost] [--rh-color] [--lh-color] [-v] [-z] [-l] [-r] [--hand-size {XXS,XS,S,M,L,XL,XXL}] [--chord-note-stagger-s] filename ``` -------------------------------- ### Default CLI Behavior Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Launches the PianoPlayer GUI when no input file is provided. ```bash pianoplayer ``` -------------------------------- ### CLI Option Details Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Lists and explains optional arguments for the PianoPlayer CLI, covering file processing, routing, and visualization. ```bash # Valid file formats: MusicXML, compressed MusicXML, MuseScore, MIDI, PIG # (.xml, .mxl, .mscz, .mscx, .mid, .midi, .txt) # # Optional arguments: # -h, --help show this help message and exit # --gui Launch the Tkinter GUI # -o , --outputfile Annotated output file name # -n , --n-measures [1000] Number of score measures to scan # -s , --start-measure Start from measure number [1] # -d , --depth [auto] Depth of combinatorial search, [5-9] # -rpart [0] Specify Right Hand part number # -lpart [1] Specify Left Hand part number # --rstaff [auto] Right-hand staff number for single-part MusicXML # --lstaff [auto] Left-hand staff number for single-part MusicXML # --auto-routing Resolve part/staff routing automatically (default) # --manual-routing Use explicit -rpart/-lpart/--rstaff/--lstaff values # --quiet Switch off verbosity # -m, --musescore Open output in musescore after processing # -b, --below-beam Show fingering numbers below beam line # --colorize-hands Colorize annotated notes/fingerings by hand # --colorize-by-cost Colorize annotated notes/fingerings by computed cost (green->red) # --rh-color [#d62828] Right hand color (hex or typical color name) # --lh-color [#1d4ed8] Left hand color (hex or typical color name) # -v, --with-vedo Play 3D scene after processing # -z, --sound-off Disable sound # -l, --left-only Fingering for left hand only # -r, --right-only Fingering for right hand only # --hand-size Hand size preset [XXS, XS, S, M, L, XL, XXL] # --chord-note-stagger-s [0.05] Small note staggering used to represent chords ``` -------------------------------- ### Basic CLI Command with Options Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Annotates a specific number of measures, enables right-hand fingering, enables 3D playback, and opens the output in MuseScore. ```bash pianoplayer scores/bach_invention4.xml -n 10 -r -v -z -m ``` -------------------------------- ### GUI Workflow Steps Source: https://github.com/marcomusy/pianoplayer/blob/master/README.md Outlines the sequence of actions to import a score, generate annotations, and visualize the results using the PianoPlayer GUI. ```text - press **Import Score** (valid formats: *MusicXML/MXL, MuseSsore, MIDI, [PIG](http://beam.kisarazu.ac.jp/~saito/research/PianoFingeringDataset/)*) - press **GENERATE** (`output.xml` for score inputs or `output.txt` for MIDI/PIG) - press **Musescore** to visualize the annotated score (Linux/macOS only) - press **Quit** (or `q` / `Ctrl+W`) to close the GUI - In **Advanced**, keep **Auto hand routing** enabled for default behavior, or disable it to set right/left part and staff manually. - In **Advanced**, you can color annotations by hand (`Colorize hands`) or by difficulty (`Colorize by cost`). ``` -------------------------------- ### Handle API Response and Download Annotated XML Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html This snippet handles the response from an API call, extracts an annotated XML file, and initiates a download. It includes error handling and updates the UI status. ```javascript new Error(data.detail || `HTTP ${response.status}`); } const blob = await response.blob(); const cd = response.headers.get("content-disposition") || ""; const match = /filename=\"([^\"]+)\\ ``` -------------------------------- ### Build and Synchronize Fingering Color Specification Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html Constructs a comma-separated string of fingering colors from input elements and updates a hidden input field. Listens for input and change events. ```javascript function buildFingeringColorSpec() { return fingerColorInputs .map((el, idx) => `${idx + 1}:${(el.value || "").trim()}`) .join(","); } function syncFingeringColorSpec() { if (!fingeringColorsEl) return; fingeringColorsEl.value = buildFingeringColorSpec(); } fingerColorInputs.forEach((el) => { el.addEventListener("input", syncFingeringColorSpec); el.addEventListener("change", syncFingeringColorSpec); }); syncFingeringColorSpec(); ``` -------------------------------- ### POST /annotate Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/README.md Annotates uploaded musical scores. Accepts multipart form-data and returns annotated files based on the input format. ```APIDOC ## POST /annotate ### Description Annotates uploaded musical scores. Accepts multipart form-data and returns annotated files based on the input format. ### Method POST ### Endpoint /annotate ### Parameters #### Request Body - **file** (multipart/form-data) - Required - The musical score file to annotate. Supported formats: `.xml`, `.mxl`, `.mid`, `.midi`, `.mscz`, `.mscx`, `.txt`. - **hand_size** (integer) - Optional - Specifies the hand size for annotation. - **depth** (integer) - Optional - Specifies the depth for annotation. - **n_measures** (integer) - Optional - Specifies the number of measures to process. - **start_measure** (integer) - Optional - Specifies the starting measure for annotation. - **left_only** (boolean) - Optional - If true, only annotates the left hand. - **right_only** (boolean) - Optional - If true, only annotates the right hand. - **below_beam** (boolean) - Optional - If true, annotates notes below the beam. - **rpart** (integer) - Optional - Specifies the right part for annotation. - **lpart** (integer) - Optional - Specifies the left part for annotation. - **chord_note_stagger_s** (float) - Optional - Specifies the stagger for chord notes. ### Response #### Success Response (200) - Annotated MusicXML attachment (`*_annotated.xml`) for MusicXML/MuseScore inputs. - Annotated tabular attachment (`*_annotated.txt`) for MIDI/PIG inputs. ``` -------------------------------- ### Synchronize Colorize Mode Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html Manages the enabled/disabled states of various colorization options (hands, cost, fingering) and their associated color pickers/fields. Ensures only one primary colorization mode is active. ```javascript function syncColorizeMode(ev) { const source = ev && ev.target; if (source) { if (source.checked) { if (source === colorizeHandsEl) { if (colorizeByCostEl) colorizeByCostEl.checked = false; if (colorizeByFingeringEl) colorizeByFingeringEl.checked = false; } else if (source === colorizeByCostEl) { if (colorizeHandsEl) colorizeHandsEl.checked = false; if (colorizeByFingeringEl) colorizeByFingeringEl.checked = false; } else if (source === colorizeByFingeringEl) { if (colorizeHandsEl) colorizeHandsEl.checked = false; if (colorizeByCostEl) colorizeByCostEl.checked = false; } } } const enabled = !!(colorizeHandsEl && colorizeHandsEl.checked); const costMode = !!(colorizeByCostEl && colorizeByCostEl.checked); const fingeringMode = !!(colorizeByFingeringEl && colorizeByFingeringEl.checked); const allowManualColor = enabled && !costMode && !fingeringMode; [rhColorEl, lhColorEl].forEach((el) => { if (!el) return; el.disabled = !allowManualColor; }); [rhColorFieldEl, lhColorFieldEl].forEach((el) => { if (!el) return; el.classList.toggle("muted", !allowManualColor); }); const allowCostColor = costMode && !enabled && !fingeringMode; if (costColormapEl) costColormapEl.disabled = !allowCostColor; if (costColormapFieldEl) costColormapFieldEl.classList.toggle("muted", !allowCostColor); const allowFingeringColor = fingeringMode && !enabled && !costMode; fingerColorInputs.forEach((el) => { el.disabled = !allowFingeringColor; }); if (fingeringColorsFieldEl) fingeringColorsFieldEl.classList.toggle("muted", !allowFingeringColor); } if (colorizeHandsEl) colorizeHandsEl.addEventListener("change", syncColorizeMode); if (colorizeByCostEl) colorizeByCostEl.addEventListener("change", syncColorizeMode); if (colorizeByFingeringEl) colorizeByFingeringEl.addEventListener("change", syncColorizeMode); syncColorizeMode(); ``` -------------------------------- ### Tab and Panel Management Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html Handles click events on tabs to switch between different content panels, managing active states and ARIA attributes. ```javascript const tabs = Array.from(document.querySelectorAll(".tab")); const panels = Array.from(document.querySelectorAll(".panel")); tabs.forEach((tab) => { tab.addEventListener("click", () => { tabs.forEach((t) => { t.classList.remove("active"); t.setAttribute("aria-selected", "false"); }); panels.forEach((p) => p.classList.remove("active")); tab.classList.add("active"); tab.setAttribute("aria-selected", "true"); const panel = document.getElementById(tab.dataset.target); if (panel) panel.classList.add("active"); }); }); ``` -------------------------------- ### File Input Change Handler Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html Updates the displayed filename in the UI when a file is selected via the file input element. Resets to default hint text if no file is selected. ```javascript fileInputEl.addEventListener("change", () => { const files = fileInputEl.files; if (files && files.length > 0) { fileHintEl.textContent = files[0].name; } else { fileHintEl.textContent = ".xml, .mxl, .mid, .midi, .mscz, .mscx, .txt"; } }); ``` -------------------------------- ### PianoPlayer JavaScript Event Listeners Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html Sets up event listeners for various form elements in the PianoPlayer web interface to handle user interactions and update UI states. ```javascript const form = document.getElementById("annotate-form"); const fileInputEl = document.getElementById("file"); const fileHintEl = document.getElementById("file-hint"); const statusEl = document.getElementById("status"); const submitBtn = document.getElementById("submit-btn"); const autoRoutingEl = document.getElementById("auto_routing"); const belowBeamEl = document.getElementById("below_beam"); const colorizeHandsEl = document.getElementById("colorize_hands"); const colorizeByCostEl = document.getElementById("colorize_by_cost"); const colorizeByFingeringEl = document.getElementById("colorize_by_fingering"); const costColormapEl = document.getElementById("cost_colormap"); const costColormapFieldEl = document.getElementById("cost_colormap_field"); const fingeringColorsEl = document.getElementById("fingering_colors"); const fingerColorInputs = [1, 2, 3, 4, 5] .map((finger) => ``` -------------------------------- ### Synchronize Routing Mode Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html Toggles the visibility of manual routing input fields based on the auto-routing setting. Ensures UI reflects the selected routing mode. ```javascript function syncRoutingMode() { const auto = autoRoutingEl.value === "true"; manualRoutingInputs.forEach((el) => { if (!el) return; const field = el.closest(".field"); if (field) field.classList.toggle("hidden", auto); }); } autoRoutingEl.addEventListener("change", syncRoutingMode); syncRoutingMode(); ``` -------------------------------- ### Form Submission Handler Source: https://github.com/marcomusy/pianoplayer/blob/master/webapi/index.html Handles the form submission event asynchronously. It prevents default submission, updates UI states, prepares form data by setting specific flags, and sends the data to the '/annotate' endpoint. ```javascript form.addEventListener("submit", async (ev) => { ev.preventDefault(); submitBtn.disabled = true; statusEl.className = "busy"; statusEl.textContent = "Processing score..."; try { const formData = new FormData(form); const handMode = formData.get("hand_mode"); formData.delete("hand_mode"); formData.set("left_only", handMode === "left" ? "true" : "false"); formData.set("right_only", handMode === "right" ? "true" : "false"); formData.set("below_beam", belowBeamEl && belowBeamEl.checked ? "true" : "false"); formData.set("colorize_hands", colorizeHandsEl && colorizeHandsEl.checked ? "true" : "false"); formData.set("colorize_by_cost", colorizeByCostEl && colorizeByCostEl.checked ? "true" : "false"); formData.set("colorize_by_fingering", colorizeByFingeringEl && colorizeByFingeringEl.checked ? "true" : "false"); syncFingeringColorSpec(); formData.set("fingering_colors", fingeringColorsEl ? fingeringColorsEl.value : ""); const response = await fetch("/annotate", { method: "POST", body: formData }); if (!response.ok) { const data = await response.json().catch(() => ({})); throw ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.