@jeffy-g/live-midi-types 0.6.1 → 0.6.3

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
@@ -1,5 +1,5 @@
1
- export * from "./midi-event";
2
- export * from "./midi-clip";
3
- export * from "./project";
4
- export * from "./ableton-colors";
5
- export declare const version = "v0.6.1";
1
+ export * from "./midi-event.js";
2
+ export * from "./midi-clip.js";
3
+ export * from "./project.js";
4
+ export * from "./ableton-colors.js";
5
+ export declare const version = "v0.6.3";
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./midi-event";
2
- export * from "./midi-clip";
3
- export * from "./project";
4
- export * from "./ableton-colors";
5
- export const version = "v0.6.1";
1
+ export * from "./midi-event.js";
2
+ export * from "./midi-clip.js";
3
+ export * from "./project.js";
4
+ export * from "./ableton-colors.js";
5
+ export const version = "v0.6.3";
@@ -9,7 +9,7 @@
9
9
  * @file src/midi-clip.ts
10
10
  * @summary Common MIDI clip data type for Ableton Live and related tools.
11
11
  */
12
- import type { NoteEvent, ControlChangeEvent } from "./midi-event";
12
+ import type { NoteEvent, ControlChangeEvent } from "./midi-event.ts";
13
13
  /**
14
14
  * MIDI clip data extracted from Ableton Live's MidiClip object.
15
15
  *
@@ -62,13 +62,24 @@ export type TempoEvent = {
62
62
  */
63
63
  bpm: number;
64
64
  };
65
- type TEventMap = {
65
+ /**
66
+ * Type alias for MIDI event types.
67
+ *
68
+ * This type maps event names to their corresponding event types.
69
+ */
70
+ export type TEventMap = {
66
71
  note: NoteEvent[];
67
72
  cc: ControlChangeEvent[];
68
73
  tempo: TempoEvent[];
69
74
  };
75
+ /**
76
+ * Type guard to check if the events array contains a specific type of MIDI event.
77
+ * @template {keyof TEventMap} K
78
+ * @param {unknown[]} events Array of events to check.
79
+ * @param {K} type Type of event to check against.
80
+ * @returns {events is TEventMap[K]} True if the events match the specified type.
81
+ */
70
82
  export declare const eventsIs: <K extends keyof TEventMap>(
71
83
  events: unknown[],
72
84
  type: K,
73
85
  ) => events is TEventMap[K];
74
- export {};
@@ -9,25 +9,33 @@
9
9
  * @file src/midi-event.ts
10
10
  * @summary Common MIDI event types for Ableton Live and related tools.
11
11
  */
12
+ /**
13
+ * @import { TEventMap } from "./midi-event.d";
14
+ */
15
+ /**
16
+ * Type guard to check if a value is an object.
17
+ * @param {unknown} value Value to check.
18
+ * @returns {value is Record<string, unknown>} True if the value is an object.
19
+ */
12
20
  function isObject(value) {
13
21
  return typeof value === "object" && value !== null;
14
22
  }
23
+ /**
24
+ * Type guard to check if the events array contains a specific type of MIDI event.
25
+ * @template {keyof TEventMap} K
26
+ * @param {unknown[]} events Array of events to check.
27
+ * @param {K} type Type of event to check against.
28
+ * @returns {events is TEventMap[K]} True if the events match the specified type.
29
+ */
15
30
  export const eventsIs = (events, type) => {
16
31
  const e = events?.[0];
32
+ if (!isObject(e)) return false;
17
33
  switch (type) {
18
34
  case "note": {
19
- return (
20
- isObject(e) &&
21
- typeof e.pitch === "number" &&
22
- typeof e.velocity === "number"
23
- );
35
+ return typeof e.pitch === "number" && typeof e.velocity === "number";
24
36
  }
25
37
  case "cc": {
26
- return (
27
- isObject(e) &&
28
- typeof e.controller === "number" &&
29
- typeof e.value === "number"
30
- );
38
+ return typeof e.controller === "number" && typeof e.value === "number";
31
39
  }
32
40
  default: {
33
41
  // tempo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffy-g/live-midi-types",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Common TypeScript types for Ableton Live MIDI clip and event data.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",