Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yjmidi

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yjmidi - npm Package Compare versions

Comparing version 1.1.0-chuchu1 to 1.2.0

5

package.json
{
"name": "yjmidi",
"version": "1.1.0-chuchu1",
"version": "1.2.0",
"main": "index.js",

@@ -9,5 +9,2 @@ "description": "midi/yjk file parser/player",

},
"bin": {
"midi2yjk": "cli/midi2yjk.js"
},
"author": "",

@@ -14,0 +11,0 @@ "license": "MIT",

26

README.md
# yjmidi
midi/yjk file parser/player
midi file parser/player
## About yjk file
The yjk(**YJK**araoke) file is a file format created for use in [yj-karaoke-player](https://github.com/kmoon2437/yj-karaoke-player).
## Usage
```js
const fs = require('fs');
const { MidiFile,YJKFile,MidiPlayer,YJKFileConverter } = require('yjmidi');
const { MidiFile,MidiPlayer } = require('yjmidi');

@@ -25,20 +22,7 @@ let midi = fs.readFileSync('...'); // your midi file. it can be an ArrayBuffer or Uint8Array or nodejs Buffer

let yjk = fs.readFileSync('...'); // your yjk file. it can be an ArrayBuffer or Uint8Array or nodejs Buffer
let file2 = new YJKFile(yjk); // YJKFile instance
file2.header; // similar to MidiFile.header
file2.globalEvents; // global events
file2.tempoEvents; // "set tempo" events
file2.ports; // the tracks separated by port
let midi2 = fs.readFileSync('...'); // your midi file. it can be an ArrayBuffer or Uint8Array or nodejs Buffer
fs.writeFileSync('./test.yjk',YJKFileConverter.midi2yjk(midi2));
/**
* Playing midi/yjk files
* Playing midi files
*/
let player = new MidiPlayer(); // MidiPlayer instance
player.loadMidi(midi); // loading a midi file
player.loadYJK(yjk); // loading a yjk file

@@ -55,4 +39,4 @@ player.on('midievent',(event,portnum,message) => {

player.tempo; // similar to HTMLMediaElement.playbackRate
player.durationTick; // same as MidiFile.header.durationTick and YJKFile.header.durationTick
player.durationMs; // same as MidiFile.header.durationMs and YJKFile.header.durationMs
player.durationTick; // same as MidiFile.header.durationTick
player.durationMs; // same as MidiFile.header.durationMs
player.currentTick;

@@ -59,0 +43,0 @@ player.currentMs;

@@ -1,2 +0,1 @@

const fs = require('fs');
const MidiFileData = require('midifile');

@@ -31,3 +30,2 @@ const MidiTrack = require('./MidiTrack');

this.ports = [];
let tracks = this.ports[0] = [];
let endtimes = [];

@@ -42,2 +40,3 @@ let endtimesMs = [];

let lastMidiEventMs = 0;
let port = 0; // 포트번호 기본값은 0
let track = new MidiTrack(i);

@@ -59,4 +58,5 @@ events.forEach((event) => {

// 포트번호 분류
if(event.subtype == Consts.events.subtypes.meta.PORT_PREFIX){
event.port = event.data[0];
port = event.port = event.data[0];
}

@@ -85,3 +85,3 @@ }else if(event.type == Consts.events.types.MIDI){

});
tracks.push(track);
this.ports[port].push(track);
endtimes.push(unsafe ? lastMidiEvent : playtick);

@@ -88,0 +88,0 @@ endtimesMs.push(unsafe ? lastMidiEventMs : playms);

@@ -11,2 +11,3 @@ const EventEmitter = require('events');

super();
if(portCount < 1) throw new RangeError('portCount(1st argument) must be >= 1. Received '+portCount);
this.portCount = portCount;

@@ -26,2 +27,3 @@ }

loadYJK(data){
console.error('Warning: YJK file is deprecated.');
if(this.playing) this.pause();

@@ -36,2 +38,43 @@ if(data instanceof YJKFile){

getPoly(port){
return this.calcPolyOfAllTracks();
if(port !== 0){
}
}
calcPoly(portNum = 0,allPorts = false){
let currentPoly = 0;
let maxPoly = 0;
let ports = allPorts ? this.d.ports : [this.d.ports[portNum]];
for(let playtick = 0;playtick <= this.durationTick;playtick++){
if(currentPoly < 0){
throw new RangeError('currentPoly must not be 0');
}
ports.forEach(port => port.forEach(track => {
let events = track.getEvents();
if(events[playtick]){
events[playtick].forEach(event => {
if(event.type == Consts.events.types.MIDI){
if(event.subtype == Consts.events.subtypes.midi.NOTE_ON){
/*if(events.params[1] == 0){ // Note on인데 velocity 0이면 note off로 처리
currentPoly--;
}else{
currentPoly++;
if(currentPoly > maxPoly) maxPoly = currentPoly;
}*/
currentPoly++;
if(currentPoly > maxPoly) maxPoly = currentPoly;
}else if(event.subtype == Consts.events.subtypes.midi.NOTE_OFF){
currentPoly--;
}
}
});
}
}));
}
console.log(currentPoly,maxPoly);
return maxPoly;
}
prepare(){

@@ -38,0 +81,0 @@ this.playms = 0;

const MidiTrack = require('./MidiTrack');
const Consts = require('./Consts');
const { BinaryXML } = require('yj-binaryxml');
const fs = require('fs');
//const { Validator:JSONSchemaValidator } = require('jsonschema');

@@ -6,0 +5,0 @@

@@ -60,2 +60,3 @@ const MidiFile = require('./MidiFile');

static midi2yjk(midiBuf,opts){
console.error('Warning: YJK file is deprecated.');
opts = Object.assign({

@@ -62,0 +63,0 @@ compress:'raw',

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc