Skip to content

Commit

Permalink
Updated for UE4.21
Browse files Browse the repository at this point in the history
Works with 4.20
  • Loading branch information
Geromatic committed Dec 12, 2018
1 parent 9def7d0 commit f76cb35
Show file tree
Hide file tree
Showing 49 changed files with 777 additions and 1,062 deletions.
7 changes: 3 additions & 4 deletions Procedural-Midi/MidiAsset/MidiAsset.uplugin
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"FileVersion" : 3,
"Version" : 13.55,
"VersionName" : "2.52.5",
"Version" : 13.72,
"VersionName" : "2.62.5",
"FriendlyName" : "Midi Asset",
"Description" : "A plugin to add MIDI capability such as importing, playing, and interfacing with MIDI files. It also includes connecting with external devices and procedural audio",
"Category" : "Audio",
"CreatedBy" : "Scott Bishel",
"CreatedByURL" : "",
"DocsURL" : "",
"EngineVersion" : "4.20.0",
"MarketplaceURL" : "com.epicgames.launcher://ue/marketplace/content/aff69119f95d405abbab38236e258c2e",
"SupportURL" : "mailto:scott.bishel@yahoo.com",
"EnabledByDefault" : true,
"CanContainContent" : true,
"IsBetaVersion" : false,
"Installed": false,
"Installed" : false,
"Modules" :
[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,12 @@ int ChannelEvent::getEventSize() {

int ChannelEvent::compareTo(MidiEvent *other) {
// Compare time
int value = MidiEvent::compareTo(other);
if (value != 0)
return value;
if (mTick != other->getTick()) {
return mTick < other->getTick() ? -1 : 1;
}
if (mDelta->getValue() != other->getDelta()) {
return mDelta->getValue() < other->getDelta() ? 1 : -1;
}

// check if other event is [not] a ChannelEvent
if (!(other->getType() >= NOTE_OFF && other->getType() <= PITCH_BEND)) {
Expand All @@ -81,9 +84,8 @@ int ChannelEvent::compareTo(MidiEvent *other) {
ChannelEvent * o = static_cast<ChannelEvent*>(other);
if (mType != o->getType()) {

int order1 = mType - PROGRAM_CHANGE;
int order2 = o->getType() - PROGRAM_CHANGE;

int order1 = getOrder(mType);
int order2 = getOrder(o->getType());
return order1 < order2 ? -1 : 1;
}
if (mValue1 != o->mValue1) {
Expand Down Expand Up @@ -127,8 +129,7 @@ void ChannelEvent::writeToFile(ostream & output, bool writeType){
}
ChannelEvent * ChannelEvent::parseChannelEvent(long tick, long delta, int type, int channel, istream & input) {
// Get Data1 value
int val1 = 0;
val1 = input.get();
int val1 = input.get();

// Get Data2 value if its not a PROGRAM_CHANGE or CHANNEL_AFTERTOUCH event
int val2 = 0;
Expand Down Expand Up @@ -156,3 +157,23 @@ ChannelEvent * ChannelEvent::parseChannelEvent(long tick, long delta, int type,

return NULL;
}

int ChannelEvent::getOrder(int type) {
switch (type) {
case PROGRAM_CHANGE:
return 0;
case CONTROLLER:
return 1;
case NOTE_ON:
return 2;
case NOTE_OFF:
return 3;
case NOTE_AFTERTOUCH:
return 4;
case CHANNEL_AFTERTOUCH:
return 5;
case PITCH_BEND:
return 6;
}
return -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ class ChannelEvent : public MidiEvent
static const int PROGRAM_CHANGE = 0xC;
static const int CHANNEL_AFTERTOUCH = 0xD;
static const int PITCH_BEND = 0xE;

private:
static int getOrder(int type);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ int EndOfTrack::getEventSize() {
void EndOfTrack::writeToFile(ostream & output) {
MetaEvent::writeToFile(output);

int size = getEventSize() - 3; // 0
output.put((char)size);
output.put((char)0); //size
}

int EndOfTrack::compareTo(MidiEvent *other) {
// Compare time
int value = MidiEvent::compareTo(other);
if (value != 0)
return value;
if (mTick != other->getTick()) {
return mTick < other->getTick() ? -1 : 1;
}
if (mDelta->getValue() != other->getDelta()) {
return mDelta->getValue() < other->getDelta() ? 1 : -1;
}

// Check events are not the same
if (!(other->getType() == this->getType())) {
// Check if same event type
if (!(other->getType() == MetaEvent::END_OF_TRACK)) {
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GenericMetaEvent::GenericMetaEvent(long tick, long delta, MetaEventData& info)
GenericMetaEvent::~GenericMetaEvent()
{
if (mData != NULL)
delete[] mData;
delete []mData;
mData = NULL;
}

Expand All @@ -29,14 +29,17 @@ void GenericMetaEvent::writeToFile(ostream & output) {
MetaEvent::writeToFile(output);

output.write(mLength->getBytes(), mLength->getByteCount());
output.write(mData, sizeof(&mData));
output.write(mData, mLength->getValue());
}

int GenericMetaEvent::compareTo(MidiEvent *other) {
// Compare time
int value = MidiEvent::compareTo(other);
if (value != 0)
return value;
if (mTick != other->getTick()) {
return mTick < other->getTick() ? -1 : 1;
}
if (mDelta->getValue() != other->getDelta()) {
return mDelta->getValue() < other->getDelta() ? 1 : -1;
}

return 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ int KeySignature::getEventSize() {
void KeySignature::writeToFile(ostream & output) {
MetaEvent::writeToFile(output);

int size = getEventSize() - 3; // 2
output.put((char)size);
output.put((char)2); //size
output.put((char)mKey);
output.put((char)mScale);
}
Expand All @@ -50,21 +49,23 @@ MetaEvent * KeySignature::parseKeySignature(long tick, long delta, MetaEventData
return new GenericMetaEvent(tick, delta, info);
}

int key = 0, scale = 0;
key = info.data[0];
scale = info.data[1];
int key = info.data[0];
int scale = info.data[1];

return new KeySignature(tick, delta, key, scale);
}

int KeySignature::compareTo(MidiEvent *other) {
// Compare time
int value = MidiEvent::compareTo(other);
if (value != 0)
return value;
if (mTick != other->getTick()) {
return mTick < other->getTick() ? -1 : 1;
}
if (mDelta->getValue() != other->getDelta()) {
return mDelta->getValue() < other->getDelta() ? 1 : -1;
}

// Check events are not the same
if (!(other->getType() == this->getType())) {
// Check if same event type
if (!(other->getType() == MetaEvent::KEY_SIGNATURE)) {
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ void MetaEvent::writeToFile(ostream & output, bool writeType) {
void MetaEvent::writeToFile(ostream & output) {
MidiEvent::writeToFile(output, true);

int status = 0XFF;
output.put((char)status);
output.put((char)(unsigned char)0XFF); // meta event
output.put((char)mType);
}

Expand Down Expand Up @@ -76,7 +75,7 @@ MetaEvent * MetaEvent::parseMetaEvent(long tick, long delta, istream & input) {
}

if (isText) {
string text = eventData.data;
string text(eventData.data, eventData.length->getValue());

switch (eventData.type) {
case TEXT_EVENT:
Expand All @@ -94,11 +93,7 @@ MetaEvent * MetaEvent::parseMetaEvent(long tick, long delta, istream & input) {
case CUE_POINT:
return new CuePoint(tick, delta, text);
case SEQUENCER_SPECIFIC:
eventData.destroy = false;
delete eventData.length;
eventData.length = NULL;

return new SequencerSpecificEvent(tick, delta, eventData.data);
return new SequencerSpecificEvent(tick, delta, new string(text));
default:
return new GenericMetaEvent(tick, delta, eventData);
}
Expand All @@ -110,9 +105,6 @@ MetaEvent * MetaEvent::parseMetaEvent(long tick, long delta, istream & input) {
case MIDI_CHANNEL_PREFIX:
return MidiChannelPrefix::parseMidiChannelPrefix(tick, delta, eventData);
case END_OF_TRACK:
// ignore next byte
// input.ignore(); // Size = 0;

return new EndOfTrack(tick, delta);
case TEMPO:
return Tempo::parseTempo(tick, delta, eventData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../MidiEvent.h"

#include <sstream>
#include <vector>
using namespace std;

/**
Expand All @@ -22,7 +23,7 @@ class MetaEvent : public MidiEvent

virtual int getEventSize() = 0;
public:
virtual void writeToFile(ostream & output, bool writeType);
/*virtual*/void writeToFile(ostream & output, bool writeType);

protected:
virtual void writeToFile(ostream & output);
Expand Down Expand Up @@ -57,7 +58,7 @@ class MetaEvent : public MidiEvent
{
if (destroy) {
delete length;
delete []data;
delete data;

length = NULL;
data = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ int MidiChannelPrefix::getEventSize() {
void MidiChannelPrefix::writeToFile(ostream & output) {
MetaEvent::writeToFile(output);

int size = getEventSize() - 3; // 1
output.put((char)size);
output.put((char)1); // size
output.put((char)mChannel);
}

Expand All @@ -36,20 +35,22 @@ MetaEvent * MidiChannelPrefix::parseMidiChannelPrefix(long tick, long delta, Met
return new GenericMetaEvent(tick, delta, info);
}

int channel = 0;
channel = info.data[0];
int channel = info.data[0];

return new MidiChannelPrefix(tick, delta, channel);
}

int MidiChannelPrefix::compareTo(MidiEvent *other) {
// Compare time
int value = MidiEvent::compareTo(other);
if (value != 0)
return value;
if (mTick != other->getTick()) {
return mTick < other->getTick() ? -1 : 1;
}
if (mDelta->getValue() != other->getDelta()) {
return mDelta->getValue() < other->getDelta() ? 1 : -1;
}

// Check events are not the same
if (!(other->getType() == this->getType())) {
// Check if same event type
if (!(other->getType() == MetaEvent::MIDI_CHANNEL_PREFIX)) {
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ int SequenceNumber::getSequenceNumber() {
void SequenceNumber::writeToFile(ostream& output) {
MetaEvent::writeToFile(output);

int size = getEventSize() - 3; // 2
output.put((char)size);
int high = getMostSignificantBits();
int low = getLeastSignificantBits();
output.put((char)high);
output.put((char)low);
output.put((char)2); // size
output.put((char)getMostSignificantBits()); // high byte
output.put((char)getLeastSignificantBits()); // low byte
}

MetaEvent* SequenceNumber::parseSequenceNumber(long tick, long delta, MetaEventData& info) {
Expand All @@ -38,22 +35,24 @@ MetaEvent* SequenceNumber::parseSequenceNumber(long tick, long delta, MetaEventD
return new GenericMetaEvent(tick, delta, info);
}

int msb = 0, lsb = 0;
msb = info.data[0];
lsb = info.data[1];
int msb = info.data[0];
int lsb = info.data[1];
int number = (msb << 8) + lsb;

return new SequenceNumber(tick, delta, number);
}

int SequenceNumber::compareTo(MidiEvent *other) {
// Compare time
int value = MidiEvent::compareTo(other);
if (value != 0)
return value;
if (mTick != other->getTick()) {
return mTick < other->getTick() ? -1 : 1;
}
if (mDelta->getValue() != other->getDelta()) {
return mDelta->getValue() < other->getDelta() ? 1 : -1;
}

// Check events are not the same
if (!(other->getType() == this->getType())) {
// Check if same event type
if (!(other->getType() == MetaEvent::SEQUENCE_NUMBER)) {
return 1;
}

Expand Down
Loading

0 comments on commit f76cb35

Please sign in to comment.