@jeffy-g/live-midi-types 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,7 +32,7 @@ npm install @jeffy-g/live-midi-types
32
32
 
33
33
  ## Ableton MIDI clip data
34
34
 
35
- `TMidiClipData` stores beat-based source data. MIDI CC events are grouped by controller in `ccMap`; `knownCCEvents` determines which controller buckets are present and their traversal order.
35
+ `TMidiClipData` stores beat-based source data and the clip's Program Change number. MIDI CC events are grouped by controller in `ccMap`; `knownCCEvents` determines which controller buckets are present and their traversal order.
36
36
 
37
37
  ```ts
38
38
  import {
@@ -60,6 +60,7 @@ const clip: TMidiClipData = {
60
60
  clipStartInBeats: 8,
61
61
  clipLength: 4,
62
62
  adjustTimeOftempee: 0,
63
+ programChange: 0,
63
64
  knownCCEvents: [64],
64
65
  notes: [note],
65
66
  ccMap: {
@@ -80,6 +81,18 @@ const controlChanges = flattenCCEventMap(
80
81
  );
81
82
  ```
82
83
 
84
+ Pass a raw-data type to `TMidiClipData` when an application also needs source-specific clip data. Omitting the generic parameter leaves the `raw` property out of the contract.
85
+
86
+ ```ts
87
+ type TRawClipData = {
88
+ currentStart: number;
89
+ currentEnd: number;
90
+ };
91
+
92
+ declare const clipWithRawData: TMidiClipData<TRawClipData>;
93
+ clipWithRawData.raw.currentStart;
94
+ ```
95
+
83
96
  ### Event value contracts
84
97
 
85
98
  All event `time` values are floating point quarter-note beats relative to the start of the clip.
@@ -110,14 +123,14 @@ The root entry point also exports `TimeSignatureEvent` and `KeySignatureEvent` f
110
123
 
111
124
  ## Project summaries
112
125
 
113
- The project types add application IDs and display metadata to clip data. `TTrackInfo.clips` is a map keyed by each `TClipSummary.id`.
126
+ The project types add application IDs and display metadata to clip data. `TTrackInfo.clips` is a map keyed by each `TClipSummary.id`. `TMidiTrackInfo` adds the MIDI output channel, while `TGeneralTrack` represents the track types that may appear in a parsed project.
114
127
 
115
128
  ```ts
116
129
  import type {
117
130
  TMidiClipData,
118
131
  TClipSummary,
132
+ TMidiTrackInfo,
119
133
  TParsedAbletonLiveSet,
120
- TTrackInfo,
121
134
  } from "@jeffy-g/live-midi-types";
122
135
 
123
136
  declare const clip: TMidiClipData;
@@ -133,12 +146,13 @@ const clipSummary: TClipSummary<TMidiClipData> = {
133
146
  ...clip,
134
147
  };
135
148
 
136
- const track: TTrackInfo<TMidiClipData> = {
149
+ const track: TMidiTrackInfo<TMidiClipData> = {
137
150
  originId: "12",
138
151
  id: "track-91d2",
139
152
  name: "Track 1",
140
153
  color: "0",
141
154
  annotation: "",
155
+ channel: 0,
142
156
  clips: {
143
157
  [clipSummary.id]: clipSummary,
144
158
  },
@@ -150,6 +164,15 @@ const project: TParsedAbletonLiveSet<TMidiClipData> = {
150
164
  tracks: [track],
151
165
  tempoAutomation: [{ time: 0, bpm: 120 }],
152
166
  };
167
+
168
+ const tracks = project.tracks;
169
+ for (let idx = 0, tracksLen = tracks.length; idx < tracksLen;) {
170
+ const currentTrack = tracks[idx++];
171
+ if ("channel" in currentTrack) {
172
+ // currentTrack.channel is number
173
+ currentTrack.channel;
174
+ }
175
+ }
153
176
  ```
154
177
 
155
178
  `color` is the Ableton palette index stored as a string. Convert it to a CSS color with `getColorFromIndex()`.
package/dist/index.d.ts CHANGED
@@ -12,4 +12,4 @@ export * from "./midi-event.js";
12
12
  export * from "./midi-clip.js";
13
13
  export * from "./project.js";
14
14
  export * from "./ableton-colors.js";
15
- export declare const version = "v0.11.0";
15
+ export declare const version = "v0.11.1";
package/dist/index.js CHANGED
@@ -12,4 +12,4 @@ export * from "./midi-event.js";
12
12
  export * from "./midi-clip.js";
13
13
  export * from "./project.js";
14
14
  export * from "./ableton-colors.js";
15
- export const version = "v0.11.0";
15
+ export const version = "v0.11.1";
@@ -21,7 +21,7 @@ import type { NoteEvent, MetaTextEvent, PitchBendEvent, ControlChangeEvent, Chan
21
21
  * const data: TMidiClipData = ...;
22
22
  * ```
23
23
  */
24
- export type TMidiClipData = {
24
+ export type TMidiClipData<GRawData = never> = {
25
25
  /**
26
26
  * Start position of the clip on the Live MidiTrack (in beats).
27
27
  */
@@ -46,6 +46,7 @@ export type TMidiClipData = {
46
46
  * Time adjustment for tempo mapping (in beats).
47
47
  */
48
48
  adjustTimeOftempee: number;
49
+ programChange: number;
49
50
  /**
50
51
  * CC numbers known to this clip, sorted in ascending order.
51
52
  *
@@ -82,7 +83,9 @@ export type TMidiClipData = {
82
83
  * @since v0.10.0
83
84
  */
84
85
  meta?: MetaTextEvent[];
85
- };
86
+ } & (
87
+ [GRawData] extends [never] ? {} : { raw: GRawData }
88
+ );
86
89
  /**
87
90
  * @param {Record<string, ControlChangeEvent[]>} ccEventMap
88
91
  * @param {number[]} knownCCEvents
package/dist/project.d.ts CHANGED
@@ -144,6 +144,17 @@ export type TTrackInfo<T extends Record<string, any>> = {
144
144
  */
145
145
  meta?: MetaTextEvent[];
146
146
  };
147
+ export type TMidiTrackInfo<T extends Record<string, any>> = TTrackInfo<T> & {
148
+ /**
149
+ * Midi Track output channel
150
+ * @since v0.11.1
151
+ */
152
+ channel: number;
153
+ };
154
+ /**
155
+ * @since v0.11.1
156
+ */
157
+ export type TGeneralTrack<T extends Record<string, any>> = TTrackInfo<T> | TMidiTrackInfo<T>;
147
158
  /**
148
159
  * Parsed data required by the Ableton Live project UI.
149
160
  */
@@ -164,8 +175,23 @@ export type TParsedAbletonLiveSet<T extends Record<string, any>> = {
164
175
  * Tracks in the project.
165
176
  *
166
177
  * + Currently contains only MIDI tracks.
178
+ *
179
+ * + Future versions may also include other track types, such as audio tracks.
180
+ *
181
+ * ```ts
182
+ * declare const als: TParsedAbletonLiveSet<Record<string, never>>;
183
+ * const tracks = als.tracks;
184
+ *
185
+ * for (let idx = 0, tracksLen = tracks.length; idx < tracksLen;) {
186
+ * const track = tracks[idx++];
187
+ * if ("channel" in track) {
188
+ * // track.channel is number
189
+ * track.channel;
190
+ * }
191
+ * }
192
+ * ```
167
193
  */
168
- tracks: Array<TTrackInfo<T>>;
194
+ tracks: Array<TGeneralTrack<T>>;
169
195
  /**
170
196
  * Tempo automation events extracted from the master track.
171
197
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffy-g/live-midi-types",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "Common TypeScript types for Ableton Live MIDI clip and event data.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",