Skip to content

Commit 6d4f230

Browse files
committed
Merge branch 'master' of github.com:RakanNimer/react-orchestra
2 parents e9eaa2b + 4357aeb commit 6d4f230

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

native/src/MidiIO/src/MidiIO.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,32 @@ class MidiIO {
8383
};
8484
return metaObject;
8585
}
86+
static indexMidiTrack(track) {
87+
const indexedTrack = track.reduce(
88+
(prev, current) => {
89+
const currentIndex = `${current.type}_${current.subtype}`;
90+
const updated = Object.assign({}, prev);
91+
if (!updated[currentIndex]) {
92+
updated[currentIndex] = [];
93+
}
94+
updated[currentIndex].push(current);
95+
return updated;
96+
},
97+
{},
98+
);
99+
return indexedTrack;
100+
}
86101
static getAllTracks(parsedMidi) {
87102
const tracks = parsedMidi.tracks.filter((track, i) => i >= 1);
88103

89104
const indexedTracks = tracks.map((track, i) => {
90-
const indexedTrack = track.reduce(
91-
(prev, current) => {
92-
const currentIndex = `${current.type}_${current.subtype}`;
93-
const updated = Object.assign({}, prev);
94-
if (!updated[currentIndex]) {
95-
updated[currentIndex] = [];
96-
}
97-
updated[currentIndex].push(current);
98-
return updated;
99-
},
100-
{},
101-
);
105+
let previousNote;
106+
const indexedTrack = MidiIO.indexMidiTrack(track);
102107
const instrumentNumber = indexedTrack.channel_programChange[0].programNumber;
103108
const instrumentName = Object.keys(INSTRUMENT_MIDI_MAPPING).find(instrumentKey => (
104109
INSTRUMENT_MIDI_MAPPING[instrumentKey] === instrumentNumber),
105110
);
111+
106112
return {
107113
controller: indexedTrack.channel_controller,
108114
programChange: indexedTrack.channel_programChange,
@@ -344,6 +350,7 @@ class MidiIO {
344350
const trackInstrumentName = meta.instrumentNames[i];
345351
const millisecondsPerTick = meta.millisecondsPerTick;
346352
let previousEndTime = 0;
353+
let previousNote = {};
347354
return noteOffs.map((noteOff) => {
348355
const {
349356
noteNumber,
@@ -360,6 +367,14 @@ class MidiIO {
360367
previousEndTime,
361368
millisecondsPerTick,
362369
);
370+
if (deltaTime === 0) {
371+
const note = Object.assign({},
372+
previousNote,
373+
{ noteNumber, noteName, instrumentName: noteInstrumentName },
374+
);
375+
previousNote = note;
376+
return note;
377+
}
363378
previousEndTime = endTimeInMS;
364379
const note = {
365380
noteNumber,
@@ -371,6 +386,7 @@ class MidiIO {
371386
deltaTime,
372387
msPerTick,
373388
};
389+
previousNote = note;
374390
return note;
375391
});
376392
});

native/src/components/MidiTrack.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class MidiTrack extends React.PureComponent {
4040
}
4141
async onTimerCall(note) {
4242
const { noteName, instrumentName, durationInMS } = note;
43-
const noteInstrumentName = this.props.instrumentName || instrumentName
43+
const noteInstrumentName = this.props.instrumentName || instrumentName;
4444
const key = generateNoteKey(noteInstrumentName, noteName);
4545
this.setState({
4646
playingNotes: {
@@ -85,6 +85,7 @@ export default class MidiTrack extends React.PureComponent {
8585
key={i}
8686
onStartPlayingNote={this.props.onNotePlayed}
8787
onStopPlayingNote={this.props.onNoteStopPlaying}
88+
delayPressOut={400}
8889
>
8990
{
9091
this.props.renderNote(instrumentName, sharpToBemol(noteName), i)

native/src/components/Note.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ class Note extends React.PureComponent {
4242
shouldComponentUpdate(nextProps, nextState) {
4343
// TODO: split into consts
4444
// return true;
45-
const shouldUpdate = this.state.isLoading || (nextProps.name !== this.props.name) || (nextProps.instrumentName !== this.props.instrumentName) || (nextState.isPlaying !== this.state.isPlaying) || (nextProps.play !== this.props.play) || this.state.isPlaying || this.state.isPlaying !== nextState.isPlaying;
45+
const isLoading = this.state.isLoading || nextState.isLoading;
46+
const isPlaying = this.state.isPlaying !== nextState.isPlaying;
47+
const isPlayingControlled = this.props.play !== nextProps.play;
48+
const shouldUpdate = isLoading || isPlaying || isPlayingControlled; // this.state.isLoading || (nextProps.name !== this.props.name) || (nextProps.instrumentName !== this.props.instrumentName) || (nextState.isPlaying !== this.state.isPlaying) || (nextProps.play !== this.props.play) || this.state.isPlaying || this.state.isPlaying !== nextState.isPlaying;
4649
return shouldUpdate;
4750
}
4851
componentWillUnmount() {

native/src/components/Orchestra.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ class Orchestra extends React.Component {
5757
<View>
5858
{ this.props.children }
5959
{
60-
this.state.tracks.map((track, i) => (
60+
this.state.tracks
61+
.filter((track, i) => this.props.selectedTracks.indexOf(i) !== -1)
62+
.map((track, i) => (
6163
<MidiTrack
6264
onNotePlayed={this.props.onNotePlayed}
6365
onNoteStopPlaying={this.props.onNoteStopPlaying}
@@ -66,7 +68,7 @@ class Orchestra extends React.Component {
6668
trackIndex={i}
6769
key={i}
6870
renderNote={this.props.renderNote}
69-
play={this.props.selectedTracks.indexOf(i) > -1 && this.props.play}
71+
play={this.props.play}
7072
onInstrumentsReady={this.onInstrumentsReady}
7173
instrumentStyle={this.props.instrumentStyle}
7274
instrumentName={this.props.instrumentName || null}

0 commit comments

Comments
 (0)