Skip to content

Commit

Permalink
Exporting to proper midi channel now
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiefaye committed Feb 22, 2019
1 parent 968c319 commit 828e3cc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
3 changes: 1 addition & 2 deletions midian/css/midian.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,13 @@ th {
}

td.midichan {
width: 28px;
font-size: 14px;
border: none;
padding: none;
}

td.midiinst {
font-size: 14px;
font-size: 12px;
border: none;
padding: none;
}
Expand Down
1 change: 1 addition & 0 deletions midian/src/Midi/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class Track {
const noteOff = noteOffs.splice(offIndex, 1)[0]
this.addNote({
midi : currentNote.noteNumber,
channel: currentNote.channel,
ticks : currentNote.absoluteTime,
velocity : currentNote.velocity / 127,
durationTicks : noteOff.absoluteTime - currentNote.absoluteTime,
Expand Down
24 changes: 22 additions & 2 deletions midian/src/MidiConversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ class MidiConversion {
console.log("MidiPPQ= " + midiPPQ);
let delugePPQ = 48;
let track = midi.tracks[trackNum - 1];
let chanMask = this.channelMasks[trackNum - 1];
let chanNum = 0;

// Output all the events in this track on the lowest channel number found in it.
// so we need to find the lowest-order one bit.
if (chanMask) {
let bit = 1;
while ((bit & chanMask) === 0) {
bit = bit << 1;
chanNum++;
}
}

let notes = track.notes;
let noteCount = notes.length;
let lanes = [];
Expand Down Expand Up @@ -84,7 +97,7 @@ class MidiConversion {
let noteData = {"y": i, "noteData": laneh}
trout.noteRows.noteRow.push(noteData);
}
// trout.midiChannel = midi.header.
trout.midiChannel = chanNum;
trout.trackLength = clipMax;
return trackOut;
}
Expand All @@ -97,8 +110,9 @@ class MidiConversion {
let highTime = -100000000;
let lowTicks = 100000000;
let highTicks = -100000000;

let maskList = [];
for(let tn = 0; tn < midi.tracks.length; ++tn) {
let channelMask = 0;
let track = midi.tracks[tn];
let notes = track.notes;
let noteCount = notes.length;
Expand All @@ -113,12 +127,18 @@ class MidiConversion {
let ttend = tt + n.durationTicks;
if (tt < lowTicks) lowTicks = tt;
if (ttend > highTicks) highTicks = ttend;
let c = n.channel;
if (c !== undefined) {
channelMask |= (1 << c);
}
}
maskList.push(channelMask);
}
this.lowTime = lowTime;
this.highTime = highTime;
this.lowTicks = lowTicks;
this.highTicks = highTicks;
this.channelMasks = maskList;
}

calcTrackLowTick(track, start, end) {
Expand Down
39 changes: 30 additions & 9 deletions midian/src/MidiDoc.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from "react-dom";
import $ from'./js/jquery-3.2.1.min.js';
import Midi from "./Midi/Midi.js";
import {Midi} from "./Midi/Midi.js";
import {WedgeIndicator, PushButton, CopyToClipButton} from './GUIstuff.jsx';
import {MidiConversion} from "./MidiConversion.js";
import {pasteTrackJson, getFocusDoc} from "../../xmlView/lib/SongLib.js";
Expand Down Expand Up @@ -202,24 +202,45 @@ class MidiGrid extends React.Component {
}
}

class ChannelMask extends React.Component {
render() {
let mask = this.props.channelMask;
let moreThanOne = false;
let rotating = 1;
let chanText = "";
for (let i = 1; i <= 16; ++ i) {
if ((mask & rotating) != 0) {
if (moreThanOne) {
chanText += ", ";
} else {
moreThanOne = true;
}
chanText += i.toString(10);
}
rotating <<= 1;
}
return chanText;
}
}

class MidiTrack extends React.Component {

render() {
let track = this.props.track;
let trackNum = this.props.trackNum;
let trackIndex = trackNum - 1;
let song = this.props.song;
let tname = track.name;
let inst = track.instrument;
let trackMask = this.props.converter.channelMasks[trackIndex];

return (<React.Fragment><table className='miditrack'><tbody><tr><td className='midiheadr'><table className='midihead'><tbody>
<tr>
<td className='midichan'><b>{trackNum}</b>:{track.channel}</td>
<td className='midiinst'>{tname ? track.name : null}</td>
</tr>
<tr><td colSpan='2' className='midiinst'>{inst ? <i>{inst.name}</i> : null}</td></tr>
<tr className='butnstr'><td colSpan='2' className='butnstd'>
<PushButton title='+ Song' onPush={this.addSel.bind(this)} />
<CopyToClipButton title='&rarr; Clip' getText={this.copySel.bind(this)} />
<tr><td className='midichan'><b>{trackNum}</b>:<ChannelMask channelMask={trackMask} /></td></tr>
<tr><td className='midiinst'>{tname ? track.name : null}</td></tr>
<tr><td className='midiinst'>{inst ? <i>{inst.name}</i> : null}</td></tr>
<tr className='butnstr'><td className='butnstd'>
<PushButton title='+ Song' onPush={this.addSel.bind(this)} />
<CopyToClipButton title='&rarr; Clip' getText={this.copySel.bind(this)} />
</td></tr>
</tbody></table></td>
<td><MidiGrid ref={el => this.grid = el} track={track} converter={this.props.converter} /></td></tr></tbody></table>
Expand Down

0 comments on commit 828e3cc

Please sign in to comment.