midimalist 0.0.0-stage → 1.0.0

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -2
  3. package/index.js +446 -0
  4. package/package.json +25 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Massimo Cavallo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # midimalist
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Midimalist is an interfacing layer for the Web MIDI API, encapsulated within a JavaScript class module. It is designed to be lightweight, simple, and minimalist, extending the Web MIDI API solely by providing syntactic simplifications for constructing MIDI messages.
4
+
5
+ - [midimalist](#midimalist)
6
+ - [Installation](#installation)
7
+ - [Usage](#usage)
8
+ - [Devices class](#Devices-class)
9
+ - [Note class](#Note-class)
10
+ - [PC class](#Pc-class)
11
+ - [Cc class](#Cc-class)
12
+ - [License](#license)
13
+
14
+ ## Installation
15
+
16
+ You can install this package via npm.
17
+
18
+ ```bash
19
+ npm i midimalist
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Devices class
25
+
26
+ Returns an object containing the available MIDI devices, divided into input and output subsets.
27
+
28
+ | Param | Type | Mandatory | Description |
29
+ | ----- | ---- | ----------- | --------- |
30
+ | | | | No parameters are required |
31
+
32
+ ```bash
33
+ let MIDI_DEVICES;
34
+
35
+ const _Devices = new _Midimalist.Devices();
36
+ _Devices.init().then(success => {
37
+ if (success) {
38
+ MIDI_DEVICES = _Devices;
39
+ }
40
+ });
41
+
42
+ #output : querable collection of input and output MIDI devices
43
+ ```
44
+
45
+ ### Note class
46
+
47
+ Send a note message to the selected MIDI device.
48
+
49
+ | Param | Type | Mandatory | Default | Description |
50
+ | ----- | ---- | ----------- | ------- | --------- |
51
+ | output | object | true | none | MIDI device from Devices class |
52
+ | play | bool | false | true | true = play note - false = note off |
53
+ | channel | integer | false | 1 | MIDI channel where to send note [1-16] |
54
+ | note | string | false | 'C4' | note to play |
55
+ | velocity | integer | false | 127 | note velocity [0-127] |
56
+ | delayon | integer | false | 0 | delay in the execution of the note |
57
+ | velocity | integer | false | 500 | delay in the note's release |
58
+
59
+ ```bash
60
+ let notesendresult = new _Midimalist
61
+ .Note(
62
+ MIDI_DEVICES.outputs.find(device => device.name === 'JT MINI MIDI 1')
63
+ , true
64
+ , 1
65
+ , "C4"
66
+ , 127
67
+ , 0
68
+ , 1000)
69
+ .send();
70
+
71
+ #output : Submission result message.
72
+ ```
73
+
74
+ ### Pc class
75
+
76
+ Send a program change message to the selected MIDI device.
77
+
78
+ | Param | Type | Mandatory | Default | Description |
79
+ | ----- | ---- | ----------- | ------- | --------- |
80
+ | output | object | true | none | MIDI device from Devices class |
81
+ | channel | integer | false | 1 | MIDI channel where to send note [1-16] |
82
+ | program | integer | false | 1 | program to switch to |
83
+
84
+ ```bash
85
+ let pcsendresult = new _Midimalist
86
+ .Pc(
87
+ MIDI_DEVICES.outputs.find(d => d.name.includes("FM"))
88
+ , 1
89
+ , 7)
90
+ .send();
91
+
92
+ #output : Submission result message.
93
+ ```
94
+
95
+ ### Cc class
96
+
97
+ Send a control change message to the selected MIDI device.
98
+
99
+ | Param | Type | Mandatory | Default | Description |
100
+ | ----- | ---- | ----------- | ------- | --------- |
101
+ | output | object | true | none | MIDI device from Devices class |
102
+ | channel | integer | false | 1 | MIDI channel where to send note [1-16] |
103
+ | cc | integer | false | 0 | control to change |
104
+ | value | integer | false | 0 | value to assign the control |
105
+
106
+ ```bash
107
+ let ccsendresult = new _Midimalist
108
+ .Cc(
109
+ MIDI_DEVICES.outputs.find(d => d.name.includes("4000"))
110
+ , 1
111
+ , 74
112
+ , 1)
113
+ .send();
114
+
115
+ #output : Submission result message.
116
+ ```
117
+
118
+ ## License
119
+
120
+ [MIT](https://opensource.org/blog/license/mit)
package/index.js ADDED
@@ -0,0 +1,446 @@
1
+ class Midimalist {
2
+ static values =
3
+ [
4
+ { index: 0, value: 0, hexvalue: 0x00 }
5
+ , { index: 1, value: 1, hexvalue: 0x01 }
6
+ , { index: 2, value: 2, hexvalue: 0x02 }
7
+ , { index: 3, value: 3, hexvalue: 0x03 }
8
+ , { index: 4, value: 4, hexvalue: 0x04 }
9
+ , { index: 5, value: 5, hexvalue: 0x05 }
10
+ , { index: 6, value: 6, hexvalue: 0x06 }
11
+ , { index: 7, value: 7, hexvalue: 0x07 }
12
+ , { index: 8, value: 8, hexvalue: 0x08 }
13
+ , { index: 9, value: 9, hexvalue: 0x09 }
14
+ , { index: 10, value: 10, hexvalue: 0x0A }
15
+ , { index: 11, value: 11, hexvalue: 0x0B }
16
+ , { index: 12, value: 12, hexvalue: 0x0C }
17
+ , { index: 13, value: 13, hexvalue: 0x0D }
18
+ , { index: 14, value: 14, hexvalue: 0x0E }
19
+ , { index: 15, value: 15, hexvalue: 0x0F }
20
+ , { index: 16, value: 16, hexvalue: 0x10 }
21
+ , { index: 17, value: 17, hexvalue: 0x11 }
22
+ , { index: 18, value: 18, hexvalue: 0x12 }
23
+ , { index: 19, value: 19, hexvalue: 0x13 }
24
+ , { index: 20, value: 20, hexvalue: 0x14 }
25
+ , { index: 21, value: 21, hexvalue: 0x15 }
26
+ , { index: 22, value: 22, hexvalue: 0x16 }
27
+ , { index: 23, value: 23, hexvalue: 0x17 }
28
+ , { index: 24, value: 24, hexvalue: 0x18 }
29
+ , { index: 25, value: 25, hexvalue: 0x19 }
30
+ , { index: 26, value: 26, hexvalue: 0x1A }
31
+ , { index: 27, value: 27, hexvalue: 0x1B }
32
+ , { index: 28, value: 28, hexvalue: 0x1C }
33
+ , { index: 29, value: 29, hexvalue: 0x1D }
34
+ , { index: 30, value: 30, hexvalue: 0x1E }
35
+ , { index: 31, value: 31, hexvalue: 0x1F }
36
+ , { index: 32, value: 32, hexvalue: 0x20 }
37
+ , { index: 33, value: 33, hexvalue: 0x21 }
38
+ , { index: 34, value: 34, hexvalue: 0x22 }
39
+ , { index: 35, value: 35, hexvalue: 0x23 }
40
+ , { index: 36, value: 36, hexvalue: 0x24 }
41
+ , { index: 37, value: 37, hexvalue: 0x25 }
42
+ , { index: 38, value: 38, hexvalue: 0x26 }
43
+ , { index: 39, value: 39, hexvalue: 0x27 }
44
+ , { index: 40, value: 40, hexvalue: 0x28 }
45
+ , { index: 41, value: 41, hexvalue: 0x29 }
46
+ , { index: 42, value: 42, hexvalue: 0x2A }
47
+ , { index: 43, value: 43, hexvalue: 0x2B }
48
+ , { index: 44, value: 44, hexvalue: 0x2C }
49
+ , { index: 45, value: 45, hexvalue: 0x2D }
50
+ , { index: 46, value: 46, hexvalue: 0x2E }
51
+ , { index: 47, value: 47, hexvalue: 0x2F }
52
+ , { index: 48, value: 48, hexvalue: 0x30 }
53
+ , { index: 49, value: 49, hexvalue: 0x31 }
54
+ , { index: 50, value: 50, hexvalue: 0x32 }
55
+ , { index: 51, value: 51, hexvalue: 0x33 }
56
+ , { index: 52, value: 52, hexvalue: 0x34 }
57
+ , { index: 53, value: 53, hexvalue: 0x35 }
58
+ , { index: 54, value: 54, hexvalue: 0x36 }
59
+ , { index: 55, value: 55, hexvalue: 0x37 }
60
+ , { index: 56, value: 56, hexvalue: 0x38 }
61
+ , { index: 57, value: 57, hexvalue: 0x39 }
62
+ , { index: 58, value: 58, hexvalue: 0x3A }
63
+ , { index: 59, value: 59, hexvalue: 0x3B }
64
+ , { index: 60, value: 60, hexvalue: 0x3C }
65
+ , { index: 61, value: 61, hexvalue: 0x3D }
66
+ , { index: 62, value: 62, hexvalue: 0x3E }
67
+ , { index: 63, value: 63, hexvalue: 0x3F }
68
+ , { index: 64, value: 64, hexvalue: 0x40 }
69
+ , { index: 65, value: 65, hexvalue: 0x41 }
70
+ , { index: 66, value: 66, hexvalue: 0x42 }
71
+ , { index: 67, value: 67, hexvalue: 0x43 }
72
+ , { index: 68, value: 68, hexvalue: 0x44 }
73
+ , { index: 69, value: 69, hexvalue: 0x45 }
74
+ , { index: 70, value: 70, hexvalue: 0x46 }
75
+ , { index: 71, value: 71, hexvalue: 0x47 }
76
+ , { index: 72, value: 72, hexvalue: 0x48 }
77
+ , { index: 73, value: 73, hexvalue: 0x49 }
78
+ , { index: 74, value: 74, hexvalue: 0x4A }
79
+ , { index: 75, value: 75, hexvalue: 0x4B }
80
+ , { index: 76, value: 76, hexvalue: 0x4C }
81
+ , { index: 77, value: 77, hexvalue: 0x4D }
82
+ , { index: 78, value: 78, hexvalue: 0x4E }
83
+ , { index: 79, value: 79, hexvalue: 0x4F }
84
+ , { index: 80, value: 80, hexvalue: 0x50 }
85
+ , { index: 81, value: 81, hexvalue: 0x51 }
86
+ , { index: 82, value: 82, hexvalue: 0x52 }
87
+ , { index: 83, value: 83, hexvalue: 0x53 }
88
+ , { index: 84, value: 84, hexvalue: 0x54 }
89
+ , { index: 85, value: 85, hexvalue: 0x55 }
90
+ , { index: 86, value: 86, hexvalue: 0x56 }
91
+ , { index: 87, value: 87, hexvalue: 0x57 }
92
+ , { index: 88, value: 88, hexvalue: 0x58 }
93
+ , { index: 89, value: 89, hexvalue: 0x59 }
94
+ , { index: 90, value: 90, hexvalue: 0x5A }
95
+ , { index: 91, value: 91, hexvalue: 0x5B }
96
+ , { index: 92, value: 92, hexvalue: 0x5C }
97
+ , { index: 93, value: 93, hexvalue: 0x5D }
98
+ , { index: 94, value: 94, hexvalue: 0x5E }
99
+ , { index: 95, value: 95, hexvalue: 0x5F }
100
+ , { index: 96, value: 96, hexvalue: 0x60 }
101
+ , { index: 97, value: 97, hexvalue: 0x61 }
102
+ , { index: 98, value: 98, hexvalue: 0x62 }
103
+ , { index: 99, value: 99, hexvalue: 0x63 }
104
+ , { index: 100, value: 100, hexvalue: 0x64 }
105
+ , { index: 101, value: 101, hexvalue: 0x65 }
106
+ , { index: 102, value: 102, hexvalue: 0x66 }
107
+ , { index: 103, value: 103, hexvalue: 0x67 }
108
+ , { index: 104, value: 104, hexvalue: 0x68 }
109
+ , { index: 105, value: 105, hexvalue: 0x69 }
110
+ , { index: 106, value: 106, hexvalue: 0x6A }
111
+ , { index: 107, value: 107, hexvalue: 0x6B }
112
+ , { index: 108, value: 108, hexvalue: 0x6C }
113
+ , { index: 109, value: 109, hexvalue: 0x6D }
114
+ , { index: 110, value: 110, hexvalue: 0x6E }
115
+ , { index: 111, value: 111, hexvalue: 0x6F }
116
+ , { index: 112, value: 112, hexvalue: 0x70 }
117
+ , { index: 113, value: 113, hexvalue: 0x71 }
118
+ , { index: 114, value: 114, hexvalue: 0x72 }
119
+ , { index: 115, value: 115, hexvalue: 0x73 }
120
+ , { index: 116, value: 116, hexvalue: 0x74 }
121
+ , { index: 117, value: 117, hexvalue: 0x75 }
122
+ , { index: 118, value: 118, hexvalue: 0x76 }
123
+ , { index: 119, value: 119, hexvalue: 0x77 }
124
+ , { index: 120, value: 120, hexvalue: 0x78 }
125
+ , { index: 121, value: 121, hexvalue: 0x79 }
126
+ , { index: 122, value: 122, hexvalue: 0x7A }
127
+ , { index: 123, value: 123, hexvalue: 0x7B }
128
+ , { index: 124, value: 124, hexvalue: 0x7C }
129
+ , { index: 125, value: 125, hexvalue: 0x7D }
130
+ , { index: 126, value: 126, hexvalue: 0x7E }
131
+ , { index: 127, value: 127, hexvalue: 0x7F }
132
+ ];
133
+ static chonoffccpc =
134
+ [
135
+ { index: 0, channel: 1, hexon: 0x90, hexoff: 0x80, hexcc: 0xB0, hexpc: 0xC0 }
136
+ , { index: 1, channel: 2, hexon: 0x91, hexoff: 0x81, hexcc: 0xB1, hexpc: 0xC1 }
137
+ , { index: 2, channel: 3, hexon: 0x92, hexoff: 0x82, hexcc: 0xB2, hexpc: 0xC2 }
138
+ , { index: 3, channel: 4, hexon: 0x93, hexoff: 0x83, hexcc: 0xB3, hexpc: 0xC3 }
139
+ , { index: 4, channel: 5, hexon: 0x94, hexoff: 0x84, hexcc: 0xB4, hexpc: 0xC4 }
140
+ , { index: 5, channel: 6, hexon: 0x95, hexoff: 0x85, hexcc: 0xB5, hexpc: 0xC5 }
141
+ , { index: 6, channel: 7, hexon: 0x96, hexoff: 0x86, hexcc: 0xB6, hexpc: 0xC6 }
142
+ , { index: 7, channel: 8, hexon: 0x97, hexoff: 0x87, hexcc: 0xB7, hexpc: 0xC7 }
143
+ , { index: 8, channel: 9, hexon: 0x98, hexoff: 0x88, hexcc: 0xB8, hexpc: 0xC8 }
144
+ , { index: 9, channel: 10, hexon: 0x99, hexoff: 0x89, hexcc: 0xB9, hexpc: 0xC9 }
145
+ , { index: 10, channel: 11, hexon: 0x9A, hexoff: 0x8A, hexcc: 0xBA, hexpc: 0xCA }
146
+ , { index: 11, channel: 12, hexon: 0x9B, hexoff: 0x8B, hexcc: 0xBB, hexpc: 0xCC }
147
+ , { index: 12, channel: 13, hexon: 0x9C, hexoff: 0x8C, hexcc: 0xBC, hexpc: 0xCC }
148
+ , { index: 13, channel: 14, hexon: 0x9D, hexoff: 0x8D, hexcc: 0xBD, hexpc: 0xCD }
149
+ , { index: 14, channel: 15, hexon: 0x9E, hexoff: 0x8E, hexcc: 0xBE, hexpc: 0xCE }
150
+ , { index: 15, channel: 16, hexon: 0x9F, hexoff: 0x8F, hexcc: 0xBF, hexpc: 0xCF }
151
+ ];
152
+ static notes =
153
+ [
154
+ { index: 0, note: 'C-1', hexnote: 0x00 }
155
+ , { index: 1, note: 'C#-1', hexnote: 0x01 }
156
+ , { index: 2, note: 'D-1', hexnote: 0x02 }
157
+ , { index: 3, note: 'D#-1', hexnote: 0x03 }
158
+ , { index: 17, note: 'F0', hexnote: 0x11 }
159
+ , { index: 18, note: 'F#0', hexnote: 0x12 }
160
+ , { index: 19, note: 'G0', hexnote: 0x13 }
161
+ , { index: 20, note: 'G#0', hexnote: 0x14 }
162
+ , { index: 21, note: 'A0', hexnote: 0x15 }
163
+ , { index: 22, note: 'A#0', hexnote: 0x16 }
164
+ , { index: 4, note: 'E-1', hexnote: 0x04 }
165
+ , { index: 5, note: 'F-1', hexnote: 0x05 }
166
+ , { index: 6, note: 'F#-1', hexnote: 0x06 }
167
+ , { index: 7, note: 'G-1', hexnote: 0x07 }
168
+ , { index: 8, note: 'G#-1', hexnote: 0x08 }
169
+ , { index: 9, note: 'A-1', hexnote: 0x09 }
170
+ , { index: 10, note: 'A#-1', hexnote: 0x0A }
171
+ , { index: 11, note: 'B-1', hexnote: 0x0B }
172
+ , { index: 12, note: 'C0', hexnote: 0x0C }
173
+ , { index: 13, note: 'C#0', hexnote: 0x0D }
174
+ , { index: 14, note: 'D0', hexnote: 0x0E }
175
+ , { index: 1, note: 'D#0', hexnote: 0x0F }
176
+ , { index: 16, note: 'E0', hexnote: 0x10 }
177
+ , { index: 17, note: 'F0', hexnote: 0x11 }
178
+ , { index: 18, note: 'F#0', hexnote: 0x12 }
179
+ , { index: 19, note: 'G0', hexnote: 0x13 }
180
+ , { index: 20, note: 'G#0', hexnote: 0x14 }
181
+ , { index: 21, note: 'A0', hexnote: 0x15 }
182
+ , { index: 22, note: 'A#0', hexnote: 0x16 }
183
+ , { index: 23, note: 'B0', hexnote: 0x17 }
184
+ , { index: 24, note: 'C1', hexnote: 0x18 }
185
+ , { index: 25, note: 'C#1', hexnote: 0x19 }
186
+ , { index: 26, note: 'D1', hexnote: 0x1A }
187
+ , { index: 27, note: 'D#1', hexnote: 0x1B }
188
+ , { index: 28, note: 'E1', hexnote: 0x1C }
189
+ , { index: 29, note: 'F1', hexnote: 0x1D }
190
+ , { index: 30, note: 'F#1', hexnote: 0x1E }
191
+ , { index: 31, note: 'G1', hexnote: 0x1F }
192
+ , { index: 32, note: 'G#1', hexnote: 0x20 }
193
+ , { index: 33, note: 'A1', hexnote: 0x21 }
194
+ , { index: 34, note: 'A#1', hexnote: 0x22 }
195
+ , { index: 35, note: 'B1', hexnote: 0x23 }
196
+ , { index: 36, note: 'C2', hexnote: 0x24 }
197
+ , { index: 37, note: 'C#2', hexnote: 0x25 }
198
+ , { index: 38, note: 'D2', hexnote: 0x26 }
199
+ , { index: 39, note: 'D#2', hexnote: 0x27 }
200
+ , { index: 40, note: 'E2', hexnote: 0x28 }
201
+ , { index: 41, note: 'F2', hexnote: 0x29 }
202
+ , { index: 42, note: 'F#2', hexnote: 0x2A }
203
+ , { index: 43, note: 'G2', hexnote: 0x2B }
204
+ , { index: 44, note: 'G#2', hexnote: 0x2C }
205
+ , { index: 45, note: 'A2', hexnote: 0x2D }
206
+ , { index: 46, note: 'A#2', hexnote: 0x2E }
207
+ , { index: 47, note: 'B2', hexnote: 0x2F }
208
+ , { index: 48, note: 'C3', hexnote: 0x30 }
209
+ , { index: 49, note: 'C#3', hexnote: 0x31 }
210
+ , { index: 50, note: 'D3', hexnote: 0x32 }
211
+ , { index: 51, note: 'D#3', hexnote: 0x33 }
212
+ , { index: 52, note: 'E3', hexnote: 0x34 }
213
+ , { index: 53, note: 'F3', hexnote: 0x35 }
214
+ , { index: 54, note: 'F#3', hexnote: 0x36 }
215
+ , { index: 55, note: 'G3', hexnote: 0x37 }
216
+ , { index: 56, note: 'G#3', hexnote: 0x38 }
217
+ , { index: 57, note: 'A3', hexnote: 0x39 }
218
+ , { index: 58, note: 'A#3', hexnote: 0x3A }
219
+ , { index: 59, note: 'B3', hexnote: 0x3B }
220
+ , { index: 60, note: 'C4', hexnote: 0x3C }
221
+ , { index: 61, note: 'C#4', hexnote: 0x3D }
222
+ , { index: 62, note: 'D4', hexnote: 0x3E }
223
+ , { index: 63, note: 'D#4', hexnote: 0x3F }
224
+ , { index: 64, note: 'E4', hexnote: 0x40 }
225
+ , { index: 65, note: 'F4', hexnote: 0x41 }
226
+ , { index: 66, note: 'F#4', hexnote: 0x42 }
227
+ , { index: 67, note: 'G4', hexnote: 0x43 }
228
+ , { index: 68, note: 'G#4', hexnote: 0x44 }
229
+ , { index: 69, note: 'A4', hexnote: 0x45 }
230
+ , { index: 70, note: 'A#4', hexnote: 0x46 }
231
+ , { index: 71, note: 'B4', hexnote: 0x47 }
232
+ , { index: 72, note: 'C5', hexnote: 0x48 }
233
+ , { index: 73, note: 'C#5', hexnote: 0x49 }
234
+ , { index: 74, note: 'D5', hexnote: 0x4A }
235
+ , { index: 75, note: 'D#5', hexnote: 0x4B }
236
+ , { index: 76, note: 'E5', hexnote: 0x4C }
237
+ , { index: 77, note: 'F5', hexnote: 0x4D }
238
+ , { index: 78, note: 'F#5', hexnote: 0x4E }
239
+ , { index: 79, note: 'G5', hexnote: 0x4F }
240
+ , { index: 80, note: 'G#5', hexnote: 0x50 }
241
+ , { index: 81, note: 'A5', hexnote: 0x51 }
242
+ , { index: 82, note: 'A#5', hexnote: 0x52 }
243
+ , { index: 83, note: 'B5', hexnote: 0x53 }
244
+ , { index: 84, note: 'C6', hexnote: 0x54 }
245
+ , { index: 85, note: 'C#6', hexnote: 0x55 }
246
+ , { index: 86, note: 'D6', hexnote: 0x56 }
247
+ , { index: 87, note: 'D#6', hexnote: 0x57 }
248
+ , { index: 88, note: 'E6', hexnote: 0x58 }
249
+ , { index: 89, note: 'F6', hexnote: 0x59 }
250
+ , { index: 90, note: 'F#6', hexnote: 0x5A }
251
+ , { index: 118, note: 'A#8', hexnote: 0x76 }
252
+ , { index: 119, note: 'B8', hexnote: 0x77 }
253
+ , { index: 120, note: 'C9', hexnote: 0x78 }
254
+ , { index: 121, note: 'C#9', hexnote: 0x79 }
255
+ , { index: 122, note: 'D9', hexnote: 0x7A }
256
+ , { index: 123, note: 'D#9', hexnote: 0x7B }
257
+ , { index: 124, note: 'E9', hexnote: 0x7C }
258
+ , { index: 125, note: 'F9', hexnote: 0x7D }
259
+ , { index: 126, note: 'F#9', hexnote: 0x7E }
260
+ , { index: 127, note: 'G9', hexnote: 0x7F }
261
+ , { index: 91, note: 'G6', hexnote: 0x5B }
262
+ , { index: 92, note: 'G#6', hexnote: 0x5C }
263
+ , { index: 93, note: 'A6', hexnote: 0x5D }
264
+ , { index: 94, note: 'A#6', hexnote: 0x5E }
265
+ , { index: 95, note: 'B6', hexnote: 0x5F }
266
+ , { index: 96, note: 'C7', hexnote: 0x60 }
267
+ , { index: 97, note: 'C#7', hexnote: 0x61 }
268
+ , { index: 98, note: 'D7', hexnote: 0x62 }
269
+ , { index: 99, note: 'D#7', hexnote: 0x63 }
270
+ , { index: 100, note: 'E7', hexnote: 0x64 }
271
+ , { index: 101, note: 'F7', hexnote: 0x65 }
272
+ , { index: 102, note: 'F#7', hexnote: 0x66 }
273
+ , { index: 103, note: 'G7', hexnote: 0x67 }
274
+ , { index: 104, note: 'G#7', hexnote: 0x68 }
275
+ , { index: 105, note: 'A7', hexnote: 0x69 }
276
+ , { index: 106, note: 'A#7', hexnote: 0x6A }
277
+ , { index: 107, note: 'B7', hexnote: 0x6B }
278
+ , { index: 108, note: 'C8', hexnote: 0x6C }
279
+ , { index: 109, note: 'C#8', hexnote: 0x6D }
280
+ , { index: 110, note: 'D8', hexnote: 0x6E }
281
+ , { index: 111, note: 'D#8', hexnote: 0x6F }
282
+ , { index: 112, note: 'E8', hexnote: 0x70 }
283
+ , { index: 113, note: 'F8', hexnote: 0x71 }
284
+ , { index: 114, note: 'F#8', hexnote: 0x72 }
285
+ , { index: 115, note: 'G8', hexnote: 0x73 }
286
+ , { index: 116, note: 'G#8', hexnote: 0x74 }
287
+ , { index: 117, note: 'A8', hexnote: 0x75 }
288
+ , { index: 118, note: 'A#8', hexnote: 0x76 }
289
+ , { index: 119, note: 'B8', hexnote: 0x77 }
290
+ , { index: 120, note: 'C9', hexnote: 0x78 }
291
+ , { index: 121, note: 'C#9', hexnote: 0x79 }
292
+ , { index: 122, note: 'D9', hexnote: 0x7A }
293
+ , { index: 123, note: 'D#9', hexnote: 0x7B }
294
+ , { index: 124, note: 'E9', hexnote: 0x7C }
295
+ , { index: 125, note: 'F9', hexnote: 0x7D }
296
+ , { index: 126, note: 'F#9', hexnote: 0x7E }
297
+ , { index: 127, note: 'G9', hexnote: 0x7F }
298
+ ]
299
+ Note = class Note {
300
+ /**
301
+ * Note constructor.
302
+ * @param {output} output - MIDI device from Devices class
303
+ * @param {bool} play - true = play note - false = note off
304
+ * @param {integer} channel - MIDI channel where to send note [1-16]
305
+ * @param {string} note - note to play
306
+ * @param {integer} velocity - note velocity [0-127]
307
+ * @param {integer} delayon - delay in the execution of the note
308
+ * @param {integer} delayoff - delay in the note's release
309
+ */
310
+ constructor(output, play = true, channel = 1, note = "C4", velocity = 127, delayon = 0, delayoff = 500) {
311
+ this.output = output,
312
+ this.play = play,
313
+ this.channel = channel;
314
+ this.note = note;
315
+ this.velocity = velocity;
316
+ this.delayon = delayon;
317
+ this.delayoff = delayoff;
318
+ console.log("Note instance created");
319
+ }
320
+ send() {
321
+ let resultMsg = "";
322
+ try {
323
+ let note = Midimalist.notes.find(note => note.note === this.note).hexnote;
324
+ let channel = Midimalist.chonoffccpc.find(element => element.channel === this.channel);
325
+ if (this.play) {
326
+ this.output.send([channel.hexon, note, this.velocity], performance.now() + this.delayon);
327
+ this.output.send([channel.hexoff, note, 0], performance.now() + this.delayoff);
328
+ } else {
329
+ this.output.send([channel.hexoff, note, 0]);
330
+ }
331
+ resultMsg = `Note.send() OK`;
332
+ } catch (error) {
333
+ resultMsg = `Note.send() KO > ${error.message}`;
334
+ }
335
+ return resultMsg;
336
+ }
337
+ };
338
+ Pc = class Pc {
339
+ /**
340
+ * Pc constructor.
341
+ * @param {output} output - MIDI device from Devices class
342
+ * @param {integer} channel - MIDI channel where to send note [1-16]
343
+ * @param {integer} program - dprogram to switch to
344
+ */
345
+ constructor(output, channel = 1, program = 1) {
346
+ this.output = output,
347
+ this.channel = channel;
348
+ this.program = program;
349
+ console.log("Pc instance created");
350
+ }
351
+ send() {
352
+ let resultMsg = "";
353
+ try {
354
+ let channel = Midimalist.chonoffccpc.find(element => element.channel === this.channel);
355
+ let prg = Midimalist.values.find(element => element.index === this.program -1);
356
+ this.output.send([channel.hexpc, prg.hexvalue]);
357
+ resultMsg = `Pc.send() OK`;
358
+ } catch (error) {
359
+ resultMsg = `Pc.send() KO > ${error.message}`;
360
+ }
361
+ return resultMsg;
362
+ }
363
+ };
364
+ Cc = class Cc {
365
+ /**
366
+ * Cc constructor.
367
+ * @param {output} output - MIDI device from Devices class
368
+ * @param {integer} channel - MIDI channel where to send note [1-16]
369
+ * @param {integer} cc - control to change
370
+ * @param {integer} value - value to assign the control
371
+ */
372
+ constructor(output, channel = 1, cc = 0, value = 0) {
373
+ this.output = output,
374
+ this.channel = channel;
375
+ this.cc = cc;
376
+ this.value = value;
377
+ console.log("Cc instance created");
378
+ }
379
+ send() {
380
+ let resultMsg = "";
381
+ try {
382
+ let channel = Midimalist.chonoffccpc.find(element => element.channel === this.channel);
383
+ let cc = Midimalist.values.find(element => element.index === this.cc);
384
+ let val = Midimalist.values.find(element => element.index === this.value);
385
+ this.output.send([channel.hexcc, cc.hexvalue, val.hexvalue]);
386
+ resultMsg = `Cc.send() OK`;
387
+ } catch (error) {
388
+ resultMsg = `Cc.send() KO > ${error.message}`;
389
+ }
390
+ return resultMsg;
391
+ }
392
+ };
393
+ /**
394
+ * Devices constructor.
395
+ * @param {inputs[]} inputs - MIDI inputs Devices
396
+ * @param {outputs[]} outputs - MIDI outputs Devices
397
+ * @param {bool} initialized - MIDI Devices initialized state
398
+ */
399
+ Devices = class Devices {
400
+ constructor() {
401
+ this.inputs = [];
402
+ this.outputs = [];
403
+ this.initialized = false;
404
+ }
405
+
406
+ async init() {
407
+ if (!navigator.requestMIDIAccess) {
408
+ console.error("Web MIDI API is not supported in this browser.");
409
+ return false;
410
+ }
411
+ try {
412
+ const midiAccess = await navigator.requestMIDIAccess();
413
+ this.inputs = Array.from(midiAccess.inputs.values());
414
+ this.outputs = Array.from(midiAccess.outputs.values());
415
+ this.initialized = true;
416
+
417
+ // Listen for device connection/disconnection events
418
+ midiAccess.onstatechange = () => {
419
+ console.log("MIDI device state changed");
420
+ // Re-fetch devices if needed, or handle specific port updates
421
+ };
422
+
423
+ return true;
424
+ } catch (err) {
425
+ console.error("Failed to initialize MIDI access:", err);
426
+ return false;
427
+ }
428
+ }
429
+
430
+ getInputs() {
431
+ return this.initialized ? this.inputs : [];
432
+ }
433
+ getInputByName(devicename) {
434
+ return this.initialized ? this.inputs.find(device => device.name === devicename) : '';
435
+ }
436
+
437
+ getOutputs() {
438
+ return this.initialized ? this.outputs : [];
439
+ }
440
+ getOutputByName(devicename) {
441
+ return this.initialized ? this.outputs.find(device => device.name === devicename) : '';
442
+ }
443
+ }
444
+ }
445
+
446
+ export { Midimalist };
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "midimalist",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Web Midi API interface",
5
+ "keywords": [
6
+ "midi"
7
+ ],
8
+ "homepage": "https://github.com/cavallom/midimalist#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/cavallom/midimalist/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/cavallom/midimalist.git"
15
+ },
16
+ "license": "ISC",
17
+ "author": "Massimo Cavallo",
18
+ "type": "commonjs",
19
+ "main": "index.js",
20
+ "scripts": {
21
+ "test": "echo \"Error: no test specified\" && exit 1"
22
+ },
23
+ "files": [
24
+ "README.md",
25
+ "LICENSE"
26
+ ]
27
+ }