Skip to content

Commit 8305dd3

Browse files
committed
Added Select by Sound Variation script, Documented soundVariationMap
- Added a new script 'Select by Sound Variation' for selecting notes by variation(s) in the Note Editor (Piano View). - Documented `context.editor.activeRegion.soundVariationMap`. - Removed or updated some Attribute ID's on example scripts. - Miscellaneous edits or removals.
1 parent 8d1fbfa commit 8305dd3

31 files changed

Lines changed: 398 additions & 35 deletions

File tree

docs/context/editor.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sidebar_position: 2
3333

3434
### SelectFunctions
3535

36-
Returned by `editor.createSelectFunctions(functions)`. The journal methods (`beginMultiple`, `endMultiple`, `setJournalEnabled`, `isJournalEnabled`) are the same as `context.functions` — see [functions.md](functions.md).
36+
Returned by `context.editor.createSelectFunctions(functions)`. The journal methods (`beginMultiple`, `endMultiple`, `setJournalEnabled`, `isJournalEnabled`) are the same as `context.functions` — see [functions.md](functions.md).
3737

3838
#### Properties
3939

@@ -51,14 +51,45 @@ Returned by `editor.createSelectFunctions(functions)`. The journal methods (`beg
5151

5252
`context.editor.activeRegion` exposes the active region surface.
5353

54+
### Properties
55+
56+
| Property | Type | Writable | Example | Description |
57+
|---|---|---|---|---|
58+
| `soundVariationMap` | `object` | No || Per-region map of sound variation definitions. |
59+
60+
### Methods
61+
5462
| Method | Returns | Parameters | Description |
5563
|---|---|---|---|
5664
| `createSequenceIterator()` | `object` | (none) | Creates an iterator over the sequence's note events. |
57-
| `getSoundVariationForNote(note)` | `number` | `note` (`note event`, req): A note event from the iterator. | Returns the sound variation index. |
65+
| `getSoundVariationForNote(note)` | `number` | `note` (`note event`, req): A note event from the iterator. | Returns the 0-based sound variation index for the note (`-1` if no variation is active at the note's position). |
5866
| `getLyricsForNote(note)` | `object` | `note` (`note event`, req): A note event from the iterator. | Returns a lyrics object for events with lyrics. |
5967

6068
The [Event Object — Lyrics Events](../objects/event_object.md#lyrics-events) for the full lyrics object surface.
6169

70+
### Sound Variation Map
71+
72+
`context.editor.activeRegion.soundVariationMap` exposes the active region's sound variation definitions. The map is read-only.
73+
74+
#### Methods
75+
76+
| Method | Returns | Parameters | Description |
77+
|---|---|---|---|
78+
| `lookupVariationByID(id)` | `object` [Variation Object](#variation-object) | `id` (`number` or `string`, req): variation id to look up. | Returns the variation object for the given id (provided by `getSoundVariationForNote(note)`). |
79+
80+
#### Variation Object
81+
82+
Returned by `lookupVariationByID`.
83+
84+
| Property | Type | Writable | Example | Description |
85+
|---|---|---|---|---|
86+
| `name` | `string` | No | `"Vibrato"` | Display name of the variation. |
87+
| `id` | `number` | No | `0` | - |
88+
89+
**Example:**
90+
91+
See the [Select by Sound Variation Script](/docs/scripts/select-sound-variation.md#sound-variation-map-access) for a finished script example showing its usage.
92+
6293
## Cursor Info
6394

6495
`context.editor.cursorInfo` exposes cursor position data. The `cursorTime`, `loopStart`, and `loopEnd` properties return time objects — see [Time Object](../objects/time_object.md) for their full surface.

docs/context/functions.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Fade types:
9292

9393
| Method | Returns | Parameters | Description |
9494
|---|---|---|---|
95-
| ~~`createEvent()`~~ || (none) ||
9695
| `deleteEvent(event)` || `event` (`note event`, req): Event to delete. | Deletes an event. |
9796
| `freezePitch(event)` || `event` (`note event`, req): Event to freeze. | - |
9897
| `freezeQuantize(event)` || `event` (`note event`, req): Event to freeze. | - |
@@ -102,7 +101,6 @@ Fade types:
102101
| `modifyVelocity(event, velocity)` || `event` (`note event`, req), `velocity` (`number`, req): 0–127 or 0.0–1.0. | Changes velocity. |
103102
| `moveEvent(event, time)` || `event` (`object`, req), `time` ([Time Object](../objects/time_object.md), req) | Moves an event to a new time position. |
104103
| `muteEvent(event, mute)` || `event` (`object`, req), `mute` (`boolean`, req) | Mutes or unmutes an event. |
105-
| ~~`newMusicalTime(value)`~~ | `object` | `value` (`number`, req) ||
106104
| `quantize(event)` || `event` (`object`, req) | Quantizes an event to the grid. |
107105
| `quantizeEvent(event)` || `event` (`object`, req) | - |
108106
| `resizeEvent(event, length)` || `event` (`object`, req), `length` (`number`, req) | Resizes an event. |

docs/objects/region_object.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Only available on selected Instrument Part or the Note Editor from the `MusicEdi
1919
| `startTime` | `object` - [Time Object](time_object.md) | No || Start position as time object. |
2020
| `endTime` | `object` - [Time Object](time_object.md) | No || End position as time object. |
2121
| `lengthTime` | `object` - [Time Object](time_object.md) | No || Length as time object. |
22+
| `soundVariationMap` | `object` [Sound Variation Map](../context/editor.md#sound-variation-map) | No || Per-region map of sound variation definitions. |
2223

2324
## Methods
2425

docs/package_structure/metainfo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Manifest metadata and package identity.
88
```xml
99
<?xml version="1.0" encoding="UTF-8"?>
1010
<MetaInformation>
11-
<Attribute id="Package:ID" value="com.yourname.scriptname"/> <!-- required for simple command-only packages -->
11+
<Attribute id="Package:ID" value="yourname.scriptname"/> <!-- required -->
1212
<Attribute id="Package:Name" value="Display Name"/> <!-- optional metadata -->
1313
<Attribute id="Package:Version" value="1.0.0"/> <!-- optional metadata -->
1414
<Attribute id="Package:Vendor" value="Your Name"/> <!-- optional metadata -->

docs/scripts/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ This section documents various example scripts that demonstrate script usage and
1212
| [**Crossfade Tool**](./crossfade-tool.md) | Creates crossfades between selected audio events with control over duration, type, and bend |
1313
| [**Flam Tool**](./flam-tool.md) | Duplicates selected MIDI notes with configurable time offset and velocity to create flam articulations |
1414
| [**Marker Creator**](./marker-creator.md) | Non-blocking workspace panel with a 4×4 button grid for creating named markers during playback |
15-
| [**Multi Script Demo**](./multi-script-demo.md) | Demonstrates registering multiple scripts in a single `.package` with separate dialogs |
15+
| [**Multi Script Demo**](./multi-script-demo.md) | Demonstrates registering multiple scripts in a single `.package` with separate dialogs |
16+
| [**Select by Sound Variation**](./select-sound-variation.md) | Selects notes in the Note Editor by their Sound Variation name |
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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+
![Select by Sound Variation](/img/select-sound-variation.png)
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.

docs/skin/input_controls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ this.InputText.value = "";
396396
| **options** | Description |
397397
|---|---|
398398
| `border` | Visible field border. |
399-
| `dialogedit` | - |
399+
| `dialogedit` | Enter submits the dialog. |
400400
| `doubleclick` | - |
401401
| `email` | Email input field. |
402402
| `extended` | Extended editing. |
-34 Bytes
Binary file not shown.
-772 Bytes
Binary file not shown.
-1 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)