Skip to content

Commit

Permalink
再生前もGUIを表示するように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
agehama committed Jul 29, 2022
1 parent 73c45c9 commit bafff34
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 34 deletions.
11 changes: 6 additions & 5 deletions SFZ_MIDI_Player/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ void Main()
Optional<MidiData> midiData;

DragDrop::AcceptFilePaths(true);
Window::SetTitle(U"MIDIファイルをドラッグドロップして再生");

while (System::Update())
{
Expand Down Expand Up @@ -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
}
}
}
4 changes: 2 additions & 2 deletions SFZ_MIDI_Player/include/PianoRoll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>& midiData) const;

void drawHorizontal(int keyMin, int keyMax, const MidiData& midiData) const;
void drawHorizontal(int keyMin, int keyMax, const Optional<MidiData>& midiData) const;

void updateTick(const MidiData& midiData);

Expand Down
4 changes: 2 additions & 2 deletions SFZ_MIDI_Player/include/SamplePlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>& midiData) const;

void drawHorizontal(const PianoRoll& pianoroll, const MidiData& midiData) const;
void drawHorizontal(const PianoRoll& pianoroll, const Optional<MidiData>& midiData) const;

const NoteEvent& addEvent(uint8 key, uint8 velocity, int64 pressTimePos, int64 releaseTimePos);

Expand Down
19 changes: 16 additions & 3 deletions SFZ_MIDI_Player/source/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <MIDILoader.hpp>
#include <Utility.hpp>

void PianoRoll::drawVertical(int keyMin, int keyMax, const MidiData& midiData) const
void PianoRoll::drawVertical(int keyMin, int keyMax, const Optional<MidiData>& midiDataOpt) const
{
const double bottomY = m_area.y + m_area.h;
const double unitHeight = m_area.h / (keyMax - keyMin + 1);
Expand All @@ -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;
Expand Down Expand Up @@ -91,17 +98,23 @@ 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<MidiData>& midiDataOpt) const
{
const double leftX = m_area.x;
const double unitWidth = m_area.w / (keyMax - keyMin + 1);

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;
Expand Down
48 changes: 26 additions & 22 deletions SFZ_MIDI_Player/source/SamplePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,29 +230,31 @@ 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<MidiData>& midiDataOpt) const
{
const int octaveMin = m_octaveMin + 1;
//const int octaveMax = m_octaveMax + 1;

//const double currentTick = pianoroll.currentTick();
const double currentSeconds = pianoroll.currentSeconds();

const auto& tracks = midiData.notes();

HashTable<int, std::pair<double, int>> 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<int>(i));
if (note.beginSec <= currentSeconds && currentSeconds < note.endSec)
{
pressedKeyTick[note.key] = std::make_pair(currentSeconds - note.beginSec, static_cast<int>(i));
}
}
}
}
Expand Down Expand Up @@ -329,29 +331,31 @@ 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<MidiData>& midiDataOpt) const
{
const int octaveMin = m_octaveMin + 1;
//const int octaveMax = m_octaveMax + 1;

//const double currentTick = pianoroll.currentTick();
const double currentSeconds = pianoroll.currentSeconds();

const auto& tracks = midiData.notes();

HashTable<int, std::pair<double, int>> 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<int>(i));
if (note.beginSec <= currentSeconds && currentSeconds < note.endSec)
{
pressedKeyTick[note.key] = std::make_pair(currentSeconds - note.beginSec, static_cast<int>(i));
}
}
}
}
Expand Down

0 comments on commit bafff34

Please sign in to comment.