|
| 1 | +--- |
| 2 | +sidebar_position: 8 |
| 3 | +--- |
| 4 | + |
| 5 | +# Select by Sound Variation |
| 6 | + |
| 7 | +A Studio Pro script for selecting notes in the Note Editor by their Sound Variation name(s). |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +<details> |
| 12 | + |
| 13 | +<summary>Click for details</summary> |
| 14 | + |
| 15 | +The **Select by Sound Variation** script in this repository is a working example demonstrating: |
| 16 | + |
| 17 | +- `ListViewModel` with named items populated from `context.editor.activeRegion.soundVariationMap` |
| 18 | +- `Host.Signals.advise` to observe selection changes on the list view |
| 19 | +- `IParamObserver` and `IController` interfaces for param list integration |
| 20 | +- `context.editor.selectFunctions.selectMultiple()` for batch selection of matching notes |
| 21 | +- `context.editor.activeRegion.getSoundVariationForNote(note)` for per-note variation lookup |
| 22 | + |
| 23 | +**Source Code Files:** |
| 24 | + |
| 25 | +- [`classfactory.xml`](https://github.com/CSources/Studio-Pro-Scripting-API-Reference/blob/main/scripts/sources/select-sound-variation-source/classfactory.xml) |
| 26 | +- [`metainfo.xml`](https://github.com/CSources/Studio-Pro-Scripting-API-Reference/blob/main/scripts/sources/select-sound-variation-source/metainfo.xml) |
| 27 | +- [`main.js`](https://github.com/CSources/Studio-Pro-Scripting-API-Reference/blob/main/scripts/sources/select-sound-variation-source/main.js) |
| 28 | +- [`skin/skin.xml`](https://github.com/CSources/Studio-Pro-Scripting-API-Reference/blob/main/scripts/sources/select-sound-variation-source/skin/skin.xml) |
| 29 | + |
| 30 | +**Key features:** |
| 31 | +- Lists all Sound Variations available in the active region's Sound Variation Map |
| 32 | +- Supports multi-selection via the list view or direct text entry in the edit box |
| 33 | +- Selects matching notes in the Note Editor on apply |
| 34 | +- Reports any unmatched variation names via an alert dialog |
| 35 | + |
| 36 | +</details> |
| 37 | + |
| 38 | +[⬇ Download Package](https://raw.githubusercontent.com/CSources/Studio-Pro-Scripting-API-Reference/main/scripts/packages/select-sound-variation/Select%20by%20Sound%20Variation.package) |
| 39 | + |
| 40 | +## Overview |
| 41 | + |
| 42 | +The Select by Sound Variation script reads the Sound Variation Map from the active region and presents the available variation names in a list view. You can select one or more variations, and the script will select all notes in the region that match those variations. |
| 43 | + |
| 44 | +## User Interface Controls |
| 45 | + |
| 46 | +### Variation List |
| 47 | + |
| 48 | +- **Type:** ListView |
| 49 | +- **Description:** Displays all named Sound Variations found in the active region's Sound Variation Map. Select one or more entries to target those variations. |
| 50 | + |
| 51 | +### Variation Names (Edit Box) |
| 52 | + |
| 53 | +- **Type:** EditBox |
| 54 | +- **Description:** Displays the names of selected variations as a comma-separated list. Can also be typed into directly to target variations by name without using the ListView. |
| 55 | + |
| 56 | +## Value Calculations |
| 57 | + |
| 58 | +### Selection Mapping |
| 59 | + |
| 60 | +The script parses the comma-separated list of variation names entered in the edit box. Each name is matched case-insensitively against variations in the Sound Variation Map. |
| 61 | + |
| 62 | +```javascript |
| 63 | +var terms = raw.split(",") |
| 64 | +for (var t = 0; t < terms.length; t++) { |
| 65 | + var term = terms[t].trim() |
| 66 | + var lowerTerm = term.toLowerCase() |
| 67 | + // match against svm.lookupVariationByID(id).name |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +| Input | Matched Variation Name | Match Type | |
| 72 | +|---|---|---| |
| 73 | +| `mute` | `Mute` | Case-insensitive | |
| 74 | +| `Open` | `open` | Case-insensitive | |
| 75 | +| `HALF_MUTE` | `Half_Mute` | Case-insensitive | |
| 76 | +| `open, mute` | `Open`, `Mute` | Multiple terms | |
| 77 | + |
| 78 | +### Note Matching |
| 79 | + |
| 80 | +Once target variation indices are identified, the script iterates through the region's notes and selects those that match: |
| 81 | + |
| 82 | +```javascript |
| 83 | +var seqIt = region.createSequenceIterator() |
| 84 | +while (!seqIt.done()) { |
| 85 | + var note = seqIt.next() |
| 86 | + var idx = region.getSoundVariationForNote(note) |
| 87 | + if (targetIndices[idx]) matching.push(note) |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +## Scripting API Notes |
| 92 | + |
| 93 | +### Sound Variation Map Access |
| 94 | + |
| 95 | +The script retrieves the Sound Variation Map from the active region: |
| 96 | + |
| 97 | +```javascript |
| 98 | +var svm = region.soundVariationMap |
| 99 | +if (svm) { |
| 100 | + for (var id = 0; id < 50; id++) { |
| 101 | + var v = svm.lookupVariationByID(id) |
| 102 | + if (v && typeof v.name === "string" && v.name.length > 0) { |
| 103 | + // add to list |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +### Per-Note Variation Lookup |
| 110 | + |
| 111 | +Each note in the region can be queried for its assigned Sound Variation index: |
| 112 | + |
| 113 | +```javascript |
| 114 | +var idx = region.getSoundVariationForNote(note) |
| 115 | +``` |
| 116 | + |
| 117 | +### Multi-Select With Edit Functions |
| 118 | + |
| 119 | +The script uses `createSelectFunctions` to perform a batch select operation: |
| 120 | + |
| 121 | +```javascript |
| 122 | +var sf = editor.createSelectFunctions(context.functions) |
| 123 | +sf.executeImmediately = true |
| 124 | +sf.selectMultiple(matching) |
| 125 | +``` |
| 126 | + |
| 127 | +### Observer Pattern |
| 128 | + |
| 129 | +The script implements `IObserver` to stay notified of selection changes in the list view. When the selection in the `VariationList` changes, `notify()` is called, which updates the `VariationNames` parameter with the comma-separated names. |
| 130 | + |
| 131 | +```javascript |
| 132 | +this.notify = function(subject, msg) { |
| 133 | + if (subject === this.VariationList) { |
| 134 | + var names = [] |
| 135 | + var sel = this.VariationList.getSelectedItems() |
| 136 | + // build comma-separated list from selected item names |
| 137 | + this.VariationNames.value = names.join(", ") |
| 138 | + } |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +## Usage |
| 143 | + |
| 144 | +1. Select an Instrument Part with Sound Variations assigned. |
| 145 | +2. Run the **Select by Sound Variation** script from the Action Menu in the Note Editor or via Find Command (Ctrl/Cmd + K). |
| 146 | +3. The dialog opens listing all available Sound Variations from the region's Sound Variation Map. |
| 147 | +4. Select one or more variations from the list view (or type variation names directly into the edit box, comma-separated). |
| 148 | +5. Click **OK** to apply. |
| 149 | +6. Notes matching the selected variations will be selected in the Note Editor. |
| 150 | + |
| 151 | +## Tips |
| 152 | + |
| 153 | +- If the variations list is empty that indicates the active region does not have a Sound Variation Map to reference, select an Instrument Part containing variations. |
| 154 | +- Typing names directly in the edit box allows you to target variations without scrolling through the list. |
0 commit comments