-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement Note Types #5902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Note Types #5902
Changes from 20 commits
b205222
cfb533a
a5cf05d
df88140
7a5ad82
725169a
faa5209
9decf11
3576300
f5cc889
1df46a5
db0d0b7
6b3c75e
4b69615
89a62f6
b3511c2
dbefa9c
463050a
0054ece
fe42e97
38dd8ec
31a2bd3
43018d7
389a245
dcb41af
2ecadb0
67b0b24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
|
|
||
| #include "MidiExport.h" | ||
|
|
||
| #include "Engine.h" | ||
| #include "TrackContainer.h" | ||
| #include "DataFile.h" | ||
| #include "InstrumentTrack.h" | ||
|
|
@@ -113,6 +114,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, | |
| int base_pitch = 0; | ||
| double base_volume = 1.0; | ||
| int base_time = 0; | ||
| int base_beatLen = 16; | ||
|
||
|
|
||
| MidiNoteVector midiClip; | ||
|
|
||
|
|
@@ -128,6 +130,17 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, | |
| base_pitch += masterPitch; | ||
| } | ||
| base_volume = LocaleHelper::toDouble(it.attribute("volume", "100"))/100.0; | ||
| // From the PR 5902 forward (Note Types), the instrument XML includes the beat length | ||
| // in frames. We try to fetch it and convert to the length in ticks. If there's no beat | ||
| // length in XML, the default beat length of 16 ticks will be used. | ||
| QDomNode iNode = it.elementsByTagName("instrument").at(0); | ||
| if(!iNode.isNull()){ | ||
| QDomElement i = iNode.toElement(); | ||
| if(i.hasAttribute("beatlen")) | ||
IanCaio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| base_beatLen = i.attribute("beatlen", "0").toInt() / Engine::framesPerTick(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (n.nodeName() == "midiclip") | ||
|
|
@@ -137,7 +150,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, | |
| } | ||
|
|
||
| } | ||
| processPatternNotes(midiClip, INT_MAX); | ||
| processPatternNotes(midiClip, base_beatLen, INT_MAX); | ||
| writeMidiClipToTrack(mtrack, midiClip); | ||
| size = mtrack.writeToBuffer(buffer.data()); | ||
| midiout.writeRawData((char *)buffer.data(), size); | ||
|
|
@@ -188,6 +201,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, | |
|
|
||
| int base_pitch = 0; | ||
| double base_volume = 1.0; | ||
| int base_beatLen = 16; | ||
|
|
||
| // for each pattern in the pattern editor | ||
| for (QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling()) | ||
|
|
@@ -201,6 +215,13 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, | |
| base_pitch += masterPitch; | ||
| } | ||
| base_volume = LocaleHelper::toDouble(it.attribute("volume", "100")) / 100.0; | ||
| QDomNode iNode = it.elementsByTagName("instrument").at(0); | ||
| if(!iNode.isNull()){ | ||
| QDomElement i = iNode.toElement(); | ||
| if(i.hasAttribute("beatlen")){ | ||
IanCaio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| base_beatLen = i.attribute("beatlen", "0").toInt()/Engine::framesPerTick(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (n.nodeName() == "midiclip") | ||
|
|
@@ -247,7 +268,7 @@ bool MidiExport::tryExport(const TrackContainer::TrackList &tracks, | |
| st.pop_back(); | ||
| } | ||
|
|
||
| processPatternNotes(nv, pos); | ||
| processPatternNotes(nv, base_beatLen, pos); | ||
| writeMidiClipToTrack(mtrack, nv); | ||
|
|
||
| // next pattern track | ||
|
|
@@ -279,6 +300,7 @@ void MidiExport::writeMidiClip(MidiNoteVector &midiClip, const QDomNode& n, | |
| mnote.volume = qMin(qRound(base_volume * LocaleHelper::toDouble(note.attribute("vol", "100")) * (127.0 / 200.0)), 127); | ||
| mnote.time = base_time + note.attribute("pos", "0").toInt(); | ||
| mnote.duration = note.attribute("len", "0").toInt(); | ||
| mnote.type = static_cast<Note::Type>(note.attribute("type", "0").toInt()); | ||
| midiClip.push_back(mnote); | ||
| } | ||
| } | ||
|
|
@@ -311,14 +333,15 @@ void MidiExport::writePatternClip(MidiNoteVector& src, MidiNoteVector& dst, | |
| note.pitch = srcNote.pitch; | ||
| note.time = base + time; | ||
| note.volume = srcNote.volume; | ||
| note.type = srcNote.type; | ||
| dst.push_back(note); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| void MidiExport::processPatternNotes(MidiNoteVector& nv, int cutPos) | ||
| void MidiExport::processPatternNotes(MidiNoteVector& nv, int beatLen, int cutPos) | ||
| { | ||
| std::sort(nv.begin(), nv.end()); | ||
| int cur = INT_MAX, next = INT_MAX; | ||
|
|
@@ -329,9 +352,9 @@ void MidiExport::processPatternNotes(MidiNoteVector& nv, int cutPos) | |
| next = cur; | ||
| cur = it->time; | ||
| } | ||
| if (it->duration < 0) | ||
| if (it->type == Note::Type::Step) | ||
| { | ||
| it->duration = qMin(qMin(-it->duration, next - cur), cutPos - it->time); | ||
| it->duration = qMin(qMin(beatLen, next - cur), cutPos - it->time); | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.