Skip to content
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

Fix tempo and fifo dump #13

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
**/settings.json
**/__pycache__
**/*.pyc
**/*.pyd
**/*.pyo
**/*.so
**/.vscode
2 changes: 1 addition & 1 deletion 3rdparty/minimidi
Submodule minimidi updated 1 files
+5 −5 include/MiniMidi.hpp
23 changes: 14 additions & 9 deletions include/Score.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,28 +450,32 @@ TIME_EVENT{

#define CLASS_NAME Tempo
TIME_EVENT{
i32 tempo{};
DEFAULT_METHODS
f32 qpm{};

static constexpr auto serialize(auto & archive, auto & event){
return archive(event.time, event.qpm);
return archive(event.time, event.tempo);
}

bool operator==(const Tempo &other) const {
return this->time == other.time && this->qpm == other.qpm;
return this->time == other.time && this->tempo == other.tempo;
}

Tempo(const unit time, const f32 qpm) : TimeStamp<T>(time), qpm(qpm) {};
Tempo(const unit time, const i32 tempo): TimeStamp<T>(time), tempo(tempo) {};

template<typename U>
Tempo(const unit time, const Tempo<U>& other): TimeStamp<T>(time), qpm(other.qpm) {};
Tempo(const unit time, const Tempo<U>& other): TimeStamp<T>(time), tempo(other.tempo) {};

[[nodiscard]] double qpm() const { return 60000000.0 / static_cast<double>(tempo); }

void set_qpm(const double qpm) { tempo = static_cast<i32>(60000000.0 / qpm); }

[[nodiscard]] std::string to_string() const {
std::stringstream ss;
ss << std::fixed << std::setprecision(SS_PRECISION);
ss << "Tempo"
<< "(time=" << this->time
<< ", qpm=" << qpm
<< ", qpm=" << qpm()
<< ", ttype=" << ttype()
<< ")";
return ss.str();
Expand Down Expand Up @@ -1344,7 +1348,8 @@ Score<T>::Score(const minimidi::file::MidiFile &midi) {
break;
}
case (message::MetaType::SetTempo): {
tempos.emplace_back(cur_time, 60000000.f / static_cast<float>(msg.get_tempo()));
// tempos.emplace_back(cur_time, 60000000.f / static_cast<float>(msg.get_tempo()));
tempos.emplace_back(cur_time, msg.get_tempo());
break;
}
case (message::MetaType::KeySignature): {
Expand Down Expand Up @@ -1445,7 +1450,8 @@ minimidi::file::MidiFile Score<T>::to_midi() const {
for(const auto &tempo: tempos) {
msgs.emplace_back(message::Message::SetTempo(
this->convert_ttype<Tick>(tempo.time),
static_cast<u32>(60000000.f / tempo.qpm)
// static_cast<u32>(60000000.f / tempo.qpm)
tempo.tempo
));
}
// add lyrics
Expand Down Expand Up @@ -1505,7 +1511,6 @@ minimidi::file::MidiFile Score<T>::to_midi() const {
note.pitch, note.velocity
));
}
utils::sort_msgs(msgs);
midi.tracks.emplace_back(std::move(msgs));
}
return midi;
Expand Down
3 changes: 2 additions & 1 deletion src/symusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ py::class_<score::Tempo<T>> bind_tempo_class(py::module &m, const std::string &
const auto name = "Tempo" + name_;
return time_stamp_base<score::Tempo<T>>(m, name)
.def(py::init<unit, float>(), py::arg("time"), py::arg("qpm"))
.def_readwrite("tempo", &score::Tempo<T>::qpm);
.def_property("tempo", &Tempo<T>::qpm, &Tempo<T>::set_qpm, "The same as qpm")
.def_property("qpm", &Tempo<T>::qpm, &Tempo<T>::set_qpm, "Quarter per minute, the same as tempo");
}

// bind score::PitchBend<T>
Expand Down
Loading