Skip to content

Commit

Permalink
Updated to version 0.1.4
Browse files Browse the repository at this point in the history
- Fixed MidiPlayer
  • Loading branch information
RandyParedis committed Nov 22, 2018
1 parent 53a3fcb commit 83ab799
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.5)
set(PROJECT_NAME autoplay)
set(AUTOPLAY_VERSION "0.1.3")
set(AUTOPLAY_VERSION "0.1.4")
project(${PROJECT_NAME})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++14 ")
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ compile `cmake` of this project with the flag `-DTRNG_LOC` set to your home dire
| 17-11-2018 | Added **Brownian Motion** as a pitch algorithm.
| 18-11-2018 | Added `rest-ratio` and `length` parameters to config file.
| 18-11-2018 | Added **1/f Noise** and **Centralized** as a pitch algorithm.
| 22-11-2018 | Fixed MidiPlayer playback with ties, added `bpm` and `time` signature to styles.
47 changes: 34 additions & 13 deletions main/music/MIDIPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,24 @@ namespace autoplay {
zz::log::ProgBar pb{duration, "Playing"};
for(unsigned measure_number = 0; measure_number < duration; ++measure_number) {
std::vector<std::vector<std::vector<unsigned char>>> note_list;

int length = 0;
int bpm = 0;

for(uint8_t channel = 0; channel < score.getParts().size(); ++channel) {
auto curr_measure = score.getParts().at(channel)->getMeasures().at(measure_number);
if(curr_measure->isOverflowing()) {
logger->error("Measure ") << measure_number << " overflowing for Part " << (int)channel;
}
std::vector<std::vector<unsigned char>> nl = {};
std::vector<std::vector<unsigned char>> nl;

if(length == 0) {
length = 4 * curr_measure->getDivisions() / curr_measure->getTime().second;
}

if(bpm == 0) {
bpm = curr_measure->getBPM();
}

for(const auto& note : curr_measure->getNotes()) {
uint8_t msgch = channel;
Expand All @@ -147,26 +159,35 @@ namespace autoplay {
}
continue;
}
auto _msg = note.getOnMessage(msgch);
if(score.getParts().at(channel)->getInstruments().size() > 1 ||
score.getParts().at(channel)->getInstruments().at(0)->isPercussion()) {
if(note.getInstrument() != nullptr) {
_msg.at(1) = note.getInstrument()->getUnpitched();
std::vector<unsigned char> _msg = {};
if(!note.getTieEnd()) {
_msg = note.getOnMessage(msgch);
if(score.getParts().at(channel)->getInstruments().size() > 1 ||
score.getParts().at(channel)->getInstruments().at(0)->isPercussion()) {
if(note.getInstrument() != nullptr) {
_msg.at(1) = note.getInstrument()->getUnpitched();
}
}
}
nl.emplace_back(_msg);

for(uint8_t len = 0; len < note.getDuration() - 2; ++len) { // duration - strike - release
msg = {};
nl.emplace_back(msg);
}
_msg = note.getOffMessage(msgch);
if(score.getParts().at(channel)->getInstruments().size() > 1 ||
score.getParts().at(channel)->getInstruments().at(0)->isPercussion()) {
if(note.getInstrument() != nullptr) {
_msg.at(1) = note.getInstrument()->getUnpitched();
if(note.getTieStart()) {
msg = {};
nl.emplace_back(msg);
} else {
_msg = note.getOffMessage(msgch);
if(score.getParts().at(channel)->getInstruments().size() > 1 ||
score.getParts().at(channel)->getInstruments().at(0)->isPercussion()) {
if(note.getInstrument() != nullptr) {
_msg.at(1) = note.getInstrument()->getUnpitched();
}
}
nl.emplace_back(_msg);
}
nl.emplace_back(_msg);
}
if(!note_list.empty() && note_list.back().size() != nl.size()) {
logger->fatal("Number of messages for Measure ")
Expand All @@ -191,7 +212,7 @@ namespace autoplay {
midiout->sendMessage(&msg);
}
}
SLEEP(24);
SLEEP((int)(60 * 1000 / (bpm * length)));
}
pb.step(1);
}
Expand Down

0 comments on commit 83ab799

Please sign in to comment.