@jeffy-g/live-midi-types 0.6.0 → 0.6.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/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from "./midi-event";
2
2
  export * from "./midi-clip";
3
3
  export * from "./project";
4
4
  export * from "./ableton-colors";
5
+ export declare const version = "v0.6.1";
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export * from "./midi-event";
2
2
  export * from "./midi-clip";
3
3
  export * from "./project";
4
4
  export * from "./ableton-colors";
5
+ export const version = "v0.6.1";
@@ -62,3 +62,13 @@ export type TempoEvent = {
62
62
  */
63
63
  bpm: number;
64
64
  };
65
+ type TEventMap = {
66
+ note: NoteEvent[];
67
+ cc: ControlChangeEvent[];
68
+ tempo: TempoEvent[];
69
+ };
70
+ export declare const eventsIs: <K extends keyof TEventMap>(
71
+ events: unknown[],
72
+ type: K,
73
+ ) => events is TEventMap[K];
74
+ export {};
@@ -9,4 +9,29 @@
9
9
  * @file src/midi-event.ts
10
10
  * @summary Common MIDI event types for Ableton Live and related tools.
11
11
  */
12
- export {};
12
+ function isObject(value) {
13
+ return typeof value === "object" && value !== null;
14
+ }
15
+ export const eventsIs = (events, type) => {
16
+ const e = events?.[0];
17
+ switch (type) {
18
+ case "note": {
19
+ return (
20
+ isObject(e) &&
21
+ typeof e.pitch === "number" &&
22
+ typeof e.velocity === "number"
23
+ );
24
+ }
25
+ case "cc": {
26
+ return (
27
+ isObject(e) &&
28
+ typeof e.controller === "number" &&
29
+ typeof e.value === "number"
30
+ );
31
+ }
32
+ default: {
33
+ // tempo
34
+ return typeof e.bpm === "number";
35
+ }
36
+ }
37
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffy-g/live-midi-types",
3
- "version": "0.6.0",
3
+ "version": "0.6.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",