midi-segmentizer
Advanced tools
@@ -6,2 +6,3 @@ import { Midi, Track } from "@tonejs/midi"; | ||
| export declare const getValidTracks: (midi: Midi) => Track[]; | ||
| export declare const shiftMidi: (midi: Midi, amount: number) => void; | ||
| export declare const getSimplePartitioningArray: (arr: number[]) => number[]; | ||
@@ -8,0 +9,0 @@ export declare const getPartitioningArrayWithMax: (arr: number[], max: number) => number[]; |
+14
-3
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.processMidiFile = exports.base64ToBinary = exports.getDurationOfNotes = exports.getBeatLength = exports.sliceAndDice = exports.getPartitioningArrayWithMax = exports.getSimplePartitioningArray = exports.getValidTracks = exports.MAX_BREATH_SECONDS = void 0; | ||
| exports.processMidiFile = exports.base64ToBinary = exports.getDurationOfNotes = exports.getBeatLength = exports.sliceAndDice = exports.getPartitioningArrayWithMax = exports.getSimplePartitioningArray = exports.shiftMidi = exports.getValidTracks = exports.MAX_BREATH_SECONDS = void 0; | ||
| const notes_processor_1 = require("./notes-processor"); | ||
@@ -10,2 +10,10 @@ exports.MAX_BREATH_SECONDS = 7; | ||
| exports.getValidTracks = getValidTracks; | ||
| const shiftMidi = (midi, amount) => { | ||
| for (const track of midi.tracks) { | ||
| for (const note of track.notes) { | ||
| note.time += amount; | ||
| } | ||
| } | ||
| }; | ||
| exports.shiftMidi = shiftMidi; | ||
| const getSimplePartitioningArray = (arr) => { | ||
@@ -52,4 +60,6 @@ return arr | ||
| const processMidiFile = (midi) => { | ||
| const beatLength = (0, exports.getBeatLength)(midi.simpleBpm); | ||
| const shift = beatLength * 2; | ||
| (0, exports.shiftMidi)(midi, shift); | ||
| const tracks = (0, exports.getValidTracks)(midi); | ||
| const beatLength = (0, exports.getBeatLength)(midi.simpleBpm); | ||
| const segmentInfos = []; | ||
@@ -64,3 +74,4 @@ // segmentize | ||
| const firstNoteStartTime = notes[0].time; | ||
| const offset = firstNoteStartTime - (firstNoteStartTime % beatLength); | ||
| const minimumOffset = firstNoteStartTime - (firstNoteStartTime % beatLength); | ||
| const offset = minimumOffset - shift; | ||
| let lowestNote = Infinity; | ||
@@ -67,0 +78,0 @@ let highestNote = -Infinity; |
+1
-1
| { | ||
| "name": "midi-segmentizer", | ||
| "version": "2.0.1", | ||
| "version": "2.1.0", | ||
| "description": "break a simple midi file into monophonic segments", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+15
-2
@@ -16,2 +16,10 @@ import { Midi, Track } from "@tonejs/midi"; | ||
| export const shiftMidi = (midi: Midi, amount: number) => { | ||
| for (const track of midi.tracks) { | ||
| for (const note of track.notes) { | ||
| note.time += amount; | ||
| } | ||
| } | ||
| }; | ||
| export const getSimplePartitioningArray = (arr: number[]): number[] => { | ||
@@ -65,4 +73,7 @@ return arr | ||
| export const processMidiFile = (midi: SimpleMidi): Segment[] => { | ||
| const beatLength = getBeatLength(midi.simpleBpm); | ||
| const shift = beatLength * 2; | ||
| shiftMidi(midi, shift); | ||
| const tracks: Track[] = getValidTracks(midi); | ||
| const beatLength = getBeatLength(midi.simpleBpm); | ||
| const segmentInfos: Segment[] = []; | ||
@@ -86,3 +97,5 @@ | ||
| const firstNoteStartTime = notes[0].time; | ||
| const offset = firstNoteStartTime - (firstNoteStartTime % beatLength); | ||
| const minimumOffset = | ||
| firstNoteStartTime - (firstNoteStartTime % beatLength); | ||
| const offset = minimumOffset - shift; | ||
@@ -89,0 +102,0 @@ let lowestNote = Infinity; |
80709
0.9%1124
2.18%