diff --git a/SFZ_MIDI_Player/Main.cpp b/SFZ_MIDI_Player/Main.cpp index d8d3e5b..29b5099 100644 --- a/SFZ_MIDI_Player/Main.cpp +++ b/SFZ_MIDI_Player/Main.cpp @@ -32,6 +32,7 @@ void Main() Optional midiData; DragDrop::AcceptFilePaths(true); + Window::SetTitle(U"MIDIファイルをドラッグドロップして再生"); while (System::Update()) { @@ -83,14 +84,14 @@ void Main() if (midiData) { pianoRoll.updateTick(midiData.value()); + } #ifdef LAYOUT_HORIZONTAL - pianoRoll.drawHorizontal(player.keyMin(), player.keyMax(), midiData.value()); - player.drawHorizontal(pianoRoll, midiData.value()); + pianoRoll.drawHorizontal(player.keyMin(), player.keyMax(), midiData); + player.drawHorizontal(pianoRoll, midiData); #else - pianoRoll.drawVertical(player.keyMin(), player.keyMax(), midiData.value()); - player.drawVertical2(pianoRoll, midiData.value()); + pianoRoll.drawVertical(player.keyMin(), player.keyMax(), midiData); + player.drawVertical(pianoRoll, midiData); #endif - } } } diff --git a/SFZ_MIDI_Player/include/PianoRoll.hpp b/SFZ_MIDI_Player/include/PianoRoll.hpp index 982d4a3..b9a9d80 100644 --- a/SFZ_MIDI_Player/include/PianoRoll.hpp +++ b/SFZ_MIDI_Player/include/PianoRoll.hpp @@ -14,9 +14,9 @@ class PianoRoll m_measureWidth(measureWidth) {} - void drawVertical(int keyMin, int keyMax, const MidiData& midiData) const; + void drawVertical(int keyMin, int keyMax, const Optional& midiData) const; - void drawHorizontal(int keyMin, int keyMax, const MidiData& midiData) const; + void drawHorizontal(int keyMin, int keyMax, const Optional& midiData) const; void updateTick(const MidiData& midiData); diff --git a/SFZ_MIDI_Player/include/SamplePlayer.hpp b/SFZ_MIDI_Player/include/SamplePlayer.hpp index 1822c04..b469e31 100644 --- a/SFZ_MIDI_Player/include/SamplePlayer.hpp +++ b/SFZ_MIDI_Player/include/SamplePlayer.hpp @@ -41,9 +41,9 @@ class SamplePlayer RectF getHorizontalRect(int octaveIndex, int noteIndex, bool isWhiteKey) const; - void drawVertical2(const PianoRoll& pianoroll, const MidiData& midiData) const; + void drawVertical(const PianoRoll& pianoroll, const Optional& midiData) const; - void drawHorizontal(const PianoRoll& pianoroll, const MidiData& midiData) const; + void drawHorizontal(const PianoRoll& pianoroll, const Optional& midiData) const; const NoteEvent& addEvent(uint8 key, uint8 velocity, int64 pressTimePos, int64 releaseTimePos); diff --git a/SFZ_MIDI_Player/source/PianoRoll.cpp b/SFZ_MIDI_Player/source/PianoRoll.cpp index 01379bb..33128c8 100644 --- a/SFZ_MIDI_Player/source/PianoRoll.cpp +++ b/SFZ_MIDI_Player/source/PianoRoll.cpp @@ -3,7 +3,7 @@ #include #include -void PianoRoll::drawVertical(int keyMin, int keyMax, const MidiData& midiData) const +void PianoRoll::drawVertical(int keyMin, int keyMax, const Optional& midiDataOpt) const { const double bottomY = m_area.y + m_area.h; const double unitHeight = m_area.h / (keyMax - keyMin + 1); @@ -13,6 +13,13 @@ void PianoRoll::drawVertical(int keyMin, int keyMax, const MidiData& midiData) c const Color measureFontColor(214, 214, 214); m_area.draw(bgColor); + if (!midiDataOpt) + { + return; + } + + const auto& midiData = midiDataOpt.value(); + const double widthTick = (midiData.resolution() / 480.0) * m_area.w / m_drawScale; const double leftTick = m_currentTick; @@ -91,7 +98,7 @@ void PianoRoll::drawVertical(int keyMin, int keyMax, const MidiData& midiData) c } } -void PianoRoll::drawHorizontal(int keyMin, int keyMax, const MidiData& midiData) const +void PianoRoll::drawHorizontal(int keyMin, int keyMax, const Optional& midiDataOpt) const { const double leftX = m_area.x; const double unitWidth = m_area.w / (keyMax - keyMin + 1); @@ -99,9 +106,15 @@ void PianoRoll::drawHorizontal(int keyMin, int keyMax, const MidiData& midiData) const Color bgColor(19, 19, 22); const Color measureLineColor(214, 214, 214); const Color measureFontColor(214, 214, 214); - m_area.draw(bgColor); + if (!midiDataOpt) + { + return; + } + + const auto& midiData = midiDataOpt.value(); + const double heightTick = (midiData.resolution() / 480.0) * m_area.h / m_drawScale; const double bottomTick = m_currentTick; diff --git a/SFZ_MIDI_Player/source/SamplePlayer.cpp b/SFZ_MIDI_Player/source/SamplePlayer.cpp index dc04594..478b6da 100644 --- a/SFZ_MIDI_Player/source/SamplePlayer.cpp +++ b/SFZ_MIDI_Player/source/SamplePlayer.cpp @@ -230,7 +230,7 @@ RectF SamplePlayer::getHorizontalRect(int octaveIndex, int noteIndex, bool isWhi return RectF(noteLeftX, m_area.y, noteWidth, m_area.h * (isWhiteKey ? 1. : 2. / 3.)); } -void SamplePlayer::drawVertical2(const PianoRoll& pianoroll, const MidiData& midiData) const +void SamplePlayer::drawVertical(const PianoRoll& pianoroll, const Optional& midiDataOpt) const { const int octaveMin = m_octaveMin + 1; //const int octaveMax = m_octaveMax + 1; @@ -238,21 +238,23 @@ void SamplePlayer::drawVertical2(const PianoRoll& pianoroll, const MidiData& mid //const double currentTick = pianoroll.currentTick(); const double currentSeconds = pianoroll.currentSeconds(); - const auto& tracks = midiData.notes(); - HashTable> pressedKeyTick; - for (const auto& [i, track] : Indexed(tracks)) + if (midiDataOpt) { - if (i == 10) + const auto& tracks = midiDataOpt.value().notes(); + for (const auto& [i, track] : Indexed(tracks)) { - continue; - } + if (i == 10) + { + continue; + } - for (const auto& note : track.notes()) - { - if (note.beginSec <= currentSeconds && currentSeconds < note.endSec) + for (const auto& note : track.notes()) { - pressedKeyTick[note.key] = std::make_pair(currentSeconds - note.beginSec, static_cast(i)); + if (note.beginSec <= currentSeconds && currentSeconds < note.endSec) + { + pressedKeyTick[note.key] = std::make_pair(currentSeconds - note.beginSec, static_cast(i)); + } } } } @@ -329,7 +331,7 @@ void SamplePlayer::drawVertical2(const PianoRoll& pianoroll, const MidiData& mid } } -void SamplePlayer::drawHorizontal(const PianoRoll& pianoroll, const MidiData& midiData) const +void SamplePlayer::drawHorizontal(const PianoRoll& pianoroll, const Optional& midiDataOpt) const { const int octaveMin = m_octaveMin + 1; //const int octaveMax = m_octaveMax + 1; @@ -337,21 +339,23 @@ void SamplePlayer::drawHorizontal(const PianoRoll& pianoroll, const MidiData& mi //const double currentTick = pianoroll.currentTick(); const double currentSeconds = pianoroll.currentSeconds(); - const auto& tracks = midiData.notes(); - HashTable> pressedKeyTick; - for (const auto& [i, track] : Indexed(tracks)) + if (midiDataOpt) { - if (i == 10) + const auto& tracks = midiDataOpt.value().notes(); + for (const auto& [i, track] : Indexed(tracks)) { - continue; - } + if (i == 10) + { + continue; + } - for (const auto& note : track.notes()) - { - if (note.beginSec <= currentSeconds && currentSeconds < note.endSec) + for (const auto& note : track.notes()) { - pressedKeyTick[note.key] = std::make_pair(currentSeconds - note.beginSec, static_cast(i)); + if (note.beginSec <= currentSeconds && currentSeconds < note.endSec) + { + pressedKeyTick[note.key] = std::make_pair(currentSeconds - note.beginSec, static_cast(i)); + } } } }