Socket
Socket
Sign inDemoInstall

midiviz-prepare

Package Overview
Dependencies
5
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

test/input.mid

60

build/main.js

@@ -16,5 +16,11 @@ #!/usr/bin/env node

var minorNotes = [1, 3, 6, 8, 10];
function isMinor(note) {
return minorNotes.indexOf(note % 12) !== -1;
}
var isMinor = function (note) { return minorNotes.indexOf(note % 12) !== -1; };
var isMajor = function (note) { return !isMinor(note); };
var isNote = function (event) { return event.isNoteOn() || event.isNoteOff(); };
var isMinorNote = function (event) {
return isNote(event) && isMinor(event.getNote());
};
var isMajorNote = function (event) {
return isNote(event) && isMajor(event.getNote());
};
/**

@@ -24,25 +30,22 @@ * Split the minor notes from the first track a separate second track

function splitMinors(music) {
var trackExists = music.length > 1;
var splitTrack = trackExists ? music[1] : MidiFunctions_1.addTrack(music);
var toDelete = [];
music[0].forEach(function (event) {
if (event.isNoteOn() || event.isNoteOff()) {
if (isMinor(event.getNote())) {
splitTrack.add(event.tt, event);
toDelete.push(event);
}
}
else {
// We don't know what's this; let's just add it to the other track, too.
if (!trackExists) {
splitTrack.add(event.tt, event);
}
}
// const keys = Object.keys(music);
// console.log("Objects in main scope: ", keys);
// keys
// .filter((key) => key !== "0")
// .forEach((key) => console.log(key, ":", music[key]));
var newMusic = MidiFunctions_1.createMusic(1, music.ppqn);
var primaryTrack = MidiFunctions_1.addTrack(newMusic);
var secondaryTrack = MidiFunctions_1.addTrack(newMusic);
music[0]
.filter(function (event) { return isMajorNote(event); }) // !isMinorNote(event))
.forEach(function (event) {
primaryTrack.add(event.tt, event);
});
MidiFunctions_1.removeEvents(music[0], toDelete);
if (music.type === 0) {
music.type = 1;
console.log("Set MIDI type from 0 to 1.");
}
console.log("Moved", toDelete.length, "note events to the second track.");
music[0]
.filter(function (event) { return isMinorNote(event); }) // !isMajorNote(event))
.forEach(function (event) {
secondaryTrack.add(event.tt, event);
});
console.log("Moved", primaryTrack.length, "major note events to primary track;", secondaryTrack.length, "minor note events to secondary track.");
return newMusic;
}

@@ -52,5 +55,8 @@ function main() {

var music = MidiFunctions_1.loadMusic(args.inputFileName);
splitMinors(music);
MidiFunctions_1.saveMusic(music, args.outputFileName);
if (music.length !== 1) {
throw new Error("Sorry, but I can only handle single-track MIDI files!");
}
var newMusic = splitMinors(music);
MidiFunctions_1.saveMusic(newMusic, args.outputFileName);
}
main();
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.describe = exports.removeEvents = exports.addTrack = exports.saveMusic = exports.loadMusic = void 0;
exports.describe = exports.removeEvents = exports.addTrack = exports.saveMusic = exports.createMusic = exports.loadMusic = void 0;
var fs = require("fs");

@@ -14,2 +14,6 @@ var JZZ = require("jzz");

exports.loadMusic = loadMusic;
function createMusic(type, tempo) {
return new JZZ.MIDI.SMF(type, tempo);
}
exports.createMusic = createMusic;
function saveMusic(music, fileName) {

@@ -25,4 +29,4 @@ fs.writeFileSync(fileName, music.dump(), "binary");

exports.addTrack = addTrack;
function removeEvents(track, events) {
remove(track, function (event) { return events.indexOf(event) !== -1; });
function removeEvents(track, test) {
remove(track, test);
}

@@ -29,0 +33,0 @@ exports.removeEvents = removeEvents;

{
"name": "midiviz-prepare",
"author": "Kristof Csillag <csillag.kristof@gmail.com>",
"version": "0.0.3",
"version": "0.0.4",
"description": "A preprocessor for MIDIVisualizer",

@@ -6,0 +6,0 @@ "main": "build/main.js",

@@ -6,3 +6,9 @@ #!/usr/bin/env node

import { SMF } from "./MidiTypes";
import { addTrack, loadMusic, removeEvents, saveMusic } from "./MidiFunctions";
import {
addTrack,
createMusic,
describe,
loadMusic,
saveMusic,
} from "./MidiFunctions";
import { MIDI } from "./JZZTypes";

@@ -29,32 +35,43 @@

function isMinor(note: number) {
return minorNotes.indexOf(note % 12) !== -1;
}
const isMinor = (note: number): boolean => minorNotes.indexOf(note % 12) !== -1;
const isMajor = (note: number): boolean => !isMinor(note);
const isNote = (event: MIDI): boolean => event.isNoteOn() || event.isNoteOff();
const isMinorNote = (event: MIDI): boolean =>
isNote(event) && isMinor(event.getNote());
const isMajorNote = (event: MIDI): boolean =>
isNote(event) && isMajor(event.getNote());
/**
* Split the minor notes from the first track a separate second track
*/
function splitMinors(music: SMF) {
const trackExists = music.length > 1;
const splitTrack = trackExists ? music[1] : addTrack(music);
const toDelete: MIDI[] = [];
music[0].forEach((event) => {
if (event.isNoteOn() || event.isNoteOff()) {
if (isMinor(event.getNote())) {
splitTrack.add(event.tt, event);
toDelete.push(event);
}
} else {
// We don't know what's this; let's just add it to the other track, too.
if (!trackExists) {
splitTrack.add(event.tt, event);
}
}
});
removeEvents(music[0], toDelete);
if (music.type === 0) {
music.type = 1;
console.log("Set MIDI type from 0 to 1.");
}
console.log("Moved", toDelete.length, "note events to the second track.");
function splitMinors(music: SMF): SMF {
// const keys = Object.keys(music);
// console.log("Objects in main scope: ", keys);
// keys
// .filter((key) => key !== "0")
// .forEach((key) => console.log(key, ":", music[key]));
const newMusic = createMusic(1, music.ppqn);
const primaryTrack = addTrack(newMusic);
const secondaryTrack = addTrack(newMusic);
music[0]
.filter((event) => isMajorNote(event)) // !isMinorNote(event))
.forEach((event) => {
primaryTrack.add(event.tt, event);
});
music[0]
.filter((event) => isMinorNote(event)) // !isMajorNote(event))
.forEach((event) => {
secondaryTrack.add(event.tt, event);
});
console.log(
"Moved",
primaryTrack.length,
"major note events to primary track;",
secondaryTrack.length,
"minor note events to secondary track."
);
return newMusic;
}

@@ -65,6 +82,9 @@

const music = loadMusic(args.inputFileName);
splitMinors(music);
saveMusic(music, args.outputFileName);
if (music.length !== 1) {
throw new Error("Sorry, but I can only handle single-track MIDI files!");
}
const newMusic = splitMinors(music);
saveMusic(newMusic, args.outputFileName);
}
main();

@@ -14,2 +14,6 @@ import fs = require("fs");

export function createMusic(type: number, tempo: number): SMF {
return new (JZZ.MIDI as any).SMF(type, tempo);
}
export function saveMusic(music: SMF, fileName: string) {

@@ -25,4 +29,4 @@ fs.writeFileSync(fileName, music.dump(), "binary");

export function removeEvents(track: MIDITrack, events: MIDI[]) {
remove(track, (event) => events.indexOf(event) !== -1);
export function removeEvents(track: MIDITrack, test: (event: MIDI) => boolean) {
remove(track, test);
}

@@ -29,0 +33,0 @@

@@ -17,4 +17,5 @@ import { MIDI } from "./JZZTypes";

type: number;
ppqn: number;
player(): MIDIPlayer;
dump(): any;
}
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