Socket
Socket
Sign inDemoInstall

web-midi-recording

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.1.2

2

package.json
{
"name": "web-midi-recording",
"version": "0.1.1",
"version": "0.1.2",
"description": "Recording SMF(Standard MIDI File) from message by Web MIDI API",

@@ -5,0 +5,0 @@ "main": "src/index.js",

# web-midi-recording
## Installation
```shell
$ npm install web-midi-recording
```
[npm](https://www.npmjs.com/package/web-midi-recording)
## Quick Example

@@ -4,0 +10,0 @@ ```javascript

@@ -9,3 +9,3 @@ import 'babel-polyfill';

try {
const data = await navigator.requestMIDIAccess({ sysex: false });
const data = await navigator.requestMIDIAccess({ sysex: false })

@@ -19,4 +19,3 @@ const midiInputs = new Object();

if (!Object.keys(midiInputs).length) {
alert('MIDIデバイスがありません!');
throw new Error();
throw new Error('Valid MIDI Devices are not found');
}

@@ -30,2 +29,3 @@

} catch (e) {
console.log(e);
alert(e);

@@ -50,2 +50,6 @@ }

const playingNote = new Array();
const holdingNote = new Array();
let isHolding = false;
// それっぽく鳴らす
const soundPianoHandler = (event) => {

@@ -61,3 +65,3 @@ const { data } = event;

console.log("note on", event);
const source = context.createBufferSource();

@@ -85,5 +89,11 @@ const gainNode = context.createGain();

if (note) {
note.stopGainNode.gain.setValueAtTime(1, context.currentTime);
note.stopGainNode.gain.linearRampToValueAtTime(0, context.currentTime + 0.1);
note.source.stop(context.currentTime + 0.3);
if (isHolding) {
holdingNote[data[1]] = note;
} else {
note.stopGainNode.gain.setValueAtTime(1, context.currentTime);
note.stopGainNode.gain.linearRampToValueAtTime(0, context.currentTime + 0.1);
note.source.stop(context.currentTime + 0.3);
}
delete playingNote[data[1]];
}

@@ -93,2 +103,18 @@ }

case 0xB:
// Hold
if (data[1] === 64) {
isHolding = data[2] > 64;
if (!isHolding) {
holdingNote.forEach((note, idx) => {
note.stopGainNode.gain.setValueAtTime(1, context.currentTime);
note.stopGainNode.gain.linearRampToValueAtTime(0, context.currentTime + 0.1);
note.source.stop(context.currentTime + 0.3);
delete holdingNote[idx]
})
}
}
default:

@@ -118,3 +144,3 @@ }

linkMidiDownload.href = URL.createObjectURL(new Blob([smf]));
buttonRecordingStop.style.display = 'none';

@@ -121,0 +147,0 @@ buttonPlayRecording.style.display = 'block';

@@ -19,13 +19,9 @@ import convertMIDIRecordingToSMF from './utils/convertMIDIRecordingToSMF';

case 0x9:
if (root === 0x9 && data[2] > 0) {
// Note On
console.log("note on", event);
} else {
// Note Off
console.log("note off", data);
}
// イベント記録
case 0xA:
case 0xB:
case 0xC:
case 0xD:
case 0xE:
// record event
if (currentRecordingFlag) {
console.log(recordingData);
recordingData.tracks[currentRecordingTrackIndex].push({

@@ -32,0 +28,0 @@ data: data,

@@ -16,7 +16,6 @@ import parseUint8 from './parseUint8';

// Temp Track
// Tempo Track
p = insertUint8List(dv, p, 'MTrk');
p = insertUint8List(dv, p, [0, 0, 0, 0x0b]);
// TODO - テンポを任意の値に
p = insertUint8List(dv, p, [0, 0xff, 0x51, 0x03, 0x07, 0xA1, 0x20])
p = insertUint8List(dv, p, [0, 0xff, 0x51, 0x03, ...parseUint8(Math.floor(60 * (10 ** 6) / tempo))])
p = insertUint8List(dv, p, [0, 0xff, 0x2f, 0]);

@@ -34,3 +33,3 @@

track.forEach((event) => {
const deltaTime = Math.round((event.startTime - preEventTime) * 2 * resolution / 1000);
const deltaTime = Math.round((event.startTime - preEventTime) * (tempo / 60) * resolution / 1000);
const deltaTimeUint8 = parseUint8(deltaTime, true);

@@ -51,7 +50,7 @@

// トラック頭のデータ長を改めて上書きする
// Rewrite data size of header
insertUint8List(dv, dataSizePoint, [0, 0, 0, ...parseUint8(dataSize)].slice(-4));
});
return dv.buffer;
return dv.buffer.slice(0, p);
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc