Skip to content

Commit

Permalink
Starting to update for Deluge 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiefaye committed Nov 5, 2022
1 parent 8191a1b commit f3bea5e
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 432 deletions.
41 changes: 30 additions & 11 deletions midian/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 5 additions & 139 deletions midian/src/DelugeToMidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function clipNoteN(y, t, vel, dur, chan, timeoff, clipS, clipE, head) {


// Encode a particular Deluge track as a Midi sequence
function encodeAsMidi14(track, start, len, chan, timeoff, clipS, clipE, head) {
function encodeAsMidi(track, start, len, chan, timeoff, clipS, clipE, head) {
let endT = start + len;
let midiOut = [];
let baseT = start;
Expand All @@ -82,16 +82,15 @@ function encodeAsMidi14(track, start, len, chan, timeoff, clipS, clipE, head) {
let rowList = forceArray(track.noteRows.noteRow);
for (var rx = 0; rx < rowList.length; ++rx) {
let row = rowList[rx];
var noteData = row.noteData;
let noteData = row.noteDataWithLift;
let y = rowYfilter(row);
if (y < 0) continue;
for (var nx = 2; nx < noteData.length; nx += 20) {
let notehex = noteData.substring(nx, nx + 20);
for (var nx = 2; nx < noteData.length; nx += 22) {
let notehex = noteData.substring(nx, nx + 22);
let x = parseInt(notehex.substring(0, 8), 16);
let dur = parseInt(notehex.substring(8, 16), 16);
let vel = parseInt(notehex.substring(16, 18), 16);
// let cond = parseInt(notehex.substring(18, 20), 16);

let liftVal = parseInt(notehex.substring(18, 20), 16);
let velN = vel / 127;
let note = clipNote(y, x + baseT, velN, dur, chan, timeoff, clipS, clipE, head);
if (note) {
Expand All @@ -107,139 +106,6 @@ function encodeAsMidi14(track, start, len, chan, timeoff, clipS, clipE, head) {
return midiOut;
}

/*
// Encode a particular Deluge track as a Midi sequence
function encodeAsMidi14Old(track, start, len, chan, timeoff, clipS, clipE, head) {
let midiPPQ = head.ppq;
let endT = start + len;
let midiOut = [];
let baseT = start;
let trackLen = Number(track.trackLength);
if (!trackLen) return [];
while (baseT < endT) {
let rowList = forceArray(track.noteRows.noteRow);
for (var rx = 0; rx < rowList.length; ++rx) {
let row = rowList[rx];
var noteData = row.noteData;
let y = rowYfilter(row);
if (y < 0) continue;
for (var nx = 2; nx < noteData.length; nx += 20) {
let notehex = noteData.substring(nx, nx + 20);
let x = parseInt(notehex.substring(0, 8), 16);
let dur = parseInt(notehex.substring(8, 16), 16);
let vel = parseInt(notehex.substring(16, 18), 16);
// let cond = parseInt(notehex.substring(18, 20), 16);
let tX = Math.round((x + baseT) * midiPPQ / delugePPQ);
let tDur = Math.round(dur * midiPPQ / delugePPQ);
let velN = vel / 127;
let onTime = tX;
let offTime = onTime + tDur;
let note = new Note({midi: y, ticks: onTime, velocity: velN, channel: chan},{ticks: offTime, velocity: 0, channel: chan}, head);
midiOut.push(note);
}
}
baseT+= trackLen;
}
midiOut.sort((a,b)=>{ return a.ticks - b.ticks});
return midiOut;
}
*/

function encodeAsMidi13(track, start, len, chan, timeoff, clipS, clipE, head) {
// first walk the track and find min and max y positions
let trackLen = Number(track.trackLength);
if (!trackLen) return [];
let endT = start + len;
let midiOut = [];
let baseT = start;
console.log("Midi13 timeoff: " + timeoff + " baseT: " + baseT);
let rowList = forceArray(track.noteRows.noteRow);
while (baseT < endT) {
for (var rx = 0; rx < rowList.length; ++rx) {
let row = rowList[rx];
var noteList = forceArray(row.notes.note);
let y = rowYfilter(row);
if (y < 0) continue;
for (var nx = 0; nx < noteList.length; ++nx) {
let n = noteList[nx];
let x = Number(n.pos);
let dur = Number(n.length);
let vel = Number(n.velocity) / 127;
let note = clipNote(y, x + baseT, vel, dur, chan, timeoff, clipS, clipE, head);
if (note) {
midiOut.push(note);
}
}
}
baseT+= trackLen;
//timeoff += trackLen;
}
midiOut.sort((a,b)=>{ return a.ticks - b.ticks});
return midiOut;
}

/*
function encodeAsMidi13OLD(track, start, len, chan, timeoff, clipS, clipE, head){
// first walk the track and find min and max y positions
let midiPPQ = head.ppq;
let trackLen = Number(track.trackLength);
if (!trackLen) return [];
let endT = start + len;
let midiOut = [];
let baseT = start;
let rowList = forceArray(track.noteRows.noteRow);
while (baseT < endT) {
for (var rx = 0; rx < rowList.length; ++rx) {
let row = rowList[rx];
var noteList = forceArray(row.notes.note);
let y = rowYfilter(row);
if (y < 0) continue;
for (var nx = 0; nx < noteList.length; ++nx) {
let n = noteList[nx];
let x = Number(n.pos);
let dur = n.length;
let vel = n.velocity / 127;
let tX = Math.round((x + baseT) * midiPPQ / delugePPQ);
let tDur = Math.round(dur * midiPPQ / delugePPQ);
let onTime = tX;
let offTime = onTime + tDur;
let note = new Note({midi: y, ticks: onTime, velocity: vel, channel: chan},{ticks: offTime, velocity: 0, channel: chan}, head);
midiOut.push(note);
}
}
baseT+= trackLen;
}
midiOut.sort((a,b)=>{ return a.ticks - b.ticks});
return midiOut;
}
*/


function usesNewNoteFormat(track) {
let rowList = forceArray(track.noteRows.noteRow);
if (rowList.length === 0) return true;
for (var rx = 0; rx < rowList.length; ++rx) {
let row = rowList[rx];
if (row.noteData) return true;
if (row.notes && row.notes.note) return false;
}
return false;
}

function encodeAsMidi(track, start, len, chan, timeoff, clipS, clipE, head) {
if(usesNewNoteFormat(track)) {
return encodeAsMidi14(track, start, len, chan, timeoff, clipS, clipE, head);
} else {
return encodeAsMidi13(track, start, len, chan, timeoff, clipS, clipE, head);
}
}

function encodeInstrumentAsMidiTrack(inst, lane, song, timeoff, head)
{
Expand Down
10 changes: 5 additions & 5 deletions midian/src/MidiConversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ function hexLZ32(v) {
}




// This function returns a function bound to the
// min/max source & target ranges given.
// oMin, oMax = source
Expand Down Expand Up @@ -223,16 +221,18 @@ class MidiConversion {
// hex digits: 0-7 start
// 8-15 duration
// 16-17 velocity
// 18-19 conditionCode, default = 0x14
// 18-19 lift velocity
// 20-21 conditionCode, default = 0x14
let hStart = hexLZ32(tDstart);
let hDur = hexLZ32(tDdur);
let hVel = (tDvel + 0x100).toString(16).substring(1);
let liftVal = "40";
let hCC = "14";
let h = hStart + hDur + hVel + hCC;
let h = hStart + hDur + hVel + liftVal + hCC;
// Deluge won't accept lower-case a-f in hex constants!
laneh += h.toUpperCase();
}
let noteData = {"y": i, "noteData": laneh}
let noteData = {"y": i, "noteDataWithLift": laneh}
trout.noteRows.noteRow.push(noteData);
}
trout.midiChannel = chanNum;
Expand Down
Loading

0 comments on commit f3bea5e

Please sign in to comment.