|
@@ -5,12 +5,20 @@
|
|
|
|
|
|
|
|
|
PlaybackScreen::PlaybackScreen(Sequencer& seq)
|
|
|
- : sequencer(seq)
|
|
|
+ : beatDisplayOffset(0), sequencer(seq)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
void PlaybackScreen::enable()
|
|
|
{
|
|
|
+ if(sequencer.beats.size() == 0) {
|
|
|
+ beatDisplayOffset = 0;
|
|
|
+ } else {
|
|
|
+ beatDisplayOffset = std::min(
|
|
|
+ beatDisplayOffset,
|
|
|
+ (Player::BeatIndex)(sequencer.beats.size() - 1) / beatDisplayWidth * beatDisplayWidth
|
|
|
+ );
|
|
|
+ }
|
|
|
refreshAll();
|
|
|
parent::enable();
|
|
|
}
|
|
@@ -18,10 +26,8 @@ void PlaybackScreen::enable()
|
|
|
void PlaybackScreen::beforeBeat(Player::BeatIndex beat)
|
|
|
{
|
|
|
std::cout << "before beat #" << beat << std::endl;
|
|
|
- for(unsigned char y = 0; y < midi::Launchpad::height - 1; y++) {
|
|
|
- refresh(beat, y);
|
|
|
- refresh((beat - 1) % (midi::Launchpad::width - 1), y);
|
|
|
- }
|
|
|
+ beatDisplayOffset = beat / beatDisplayWidth * beatDisplayWidth;
|
|
|
+ refreshAll();
|
|
|
}
|
|
|
|
|
|
void PlaybackScreen::afterBeat(Player::BeatIndex beat)
|
|
@@ -39,15 +45,28 @@ void PlaybackScreen::keyPressed(unsigned char x, unsigned char y)
|
|
|
sequencer.midiOut.sendMessage(*msg_ptr);
|
|
|
}
|
|
|
} else if(y == 8) { // very top
|
|
|
- if(x == 0) {
|
|
|
- if(sequencer.player.isPlaying()) {
|
|
|
- sequencer.player.stop();
|
|
|
- } else {
|
|
|
- sequencer.player.loop();
|
|
|
- }
|
|
|
+ bool playing = sequencer.player.isPlaying();
|
|
|
+ switch(x) {
|
|
|
+ case 2: // left
|
|
|
+ if(!playing && beatDisplayOffset > 0) {
|
|
|
+ beatDisplayOffset = std::max((Player::BeatIndex)0, beatDisplayOffset - beatDisplayWidth);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: // right
|
|
|
+ if(!playing && beatDisplayOffset < (sequencer.beats.size() / beatDisplayWidth)) {
|
|
|
+ beatDisplayOffset += beatDisplayWidth;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 7: // start / stop
|
|
|
+ if(playing) {
|
|
|
+ sequencer.player.stop();
|
|
|
+ } else {
|
|
|
+ sequencer.player.loop();
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
} else {
|
|
|
- Player::BeatIndex beatIndex = x;
|
|
|
+ Player::BeatIndex beatIndex = x + beatDisplayOffset;
|
|
|
if(beatIndex < sequencer.beats.size() && y < sequencer.messages.size()) {
|
|
|
midi::MessageList& beat = sequencer.beats[beatIndex];
|
|
|
std::cout << "before ";
|
|
@@ -69,12 +88,12 @@ void PlaybackScreen::keyPressed(unsigned char x, unsigned char y)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- refresh(x, y);
|
|
|
+ refreshAll();
|
|
|
}
|
|
|
|
|
|
void PlaybackScreen::keyReleased(unsigned char x, unsigned char y)
|
|
|
{
|
|
|
- refresh(x, y);
|
|
|
+ refreshAll();
|
|
|
}
|
|
|
|
|
|
void PlaybackScreen::refresh(unsigned char x, unsigned char y)
|
|
@@ -86,16 +105,32 @@ void PlaybackScreen::refresh(unsigned char x, unsigned char y)
|
|
|
setColor(x, y, colors::dark);
|
|
|
}
|
|
|
} else if(y == 8) { // very top
|
|
|
- if(x == 0) {
|
|
|
- // start / stop
|
|
|
- if(sequencer.player.isPlaying()) {
|
|
|
- setColor(x, y, colors::activeOption);
|
|
|
- } else {
|
|
|
- setColor(x, y, colors::inactiveOption);
|
|
|
- }
|
|
|
+ bool playing = sequencer.player.isPlaying();
|
|
|
+ switch(x) {
|
|
|
+ case 2: // left
|
|
|
+ if(!playing && beatDisplayOffset > 0) {
|
|
|
+ setColor(x, y, colors::inactiveOption);
|
|
|
+ } else {
|
|
|
+ setColor(x, y, colors::dark);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3: // right
|
|
|
+ if(!playing && beatDisplayOffset < (sequencer.beats.size() / beatDisplayWidth)) {
|
|
|
+ setColor(x, y, colors::inactiveOption);
|
|
|
+ } else {
|
|
|
+ setColor(x, y, colors::dark);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 7: // start / stop
|
|
|
+ if(playing) {
|
|
|
+ setColor(x, y, colors::activeOption);
|
|
|
+ } else {
|
|
|
+ setColor(x, y, colors::inactiveOption);
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
} else {
|
|
|
- Player::BeatIndex beatIndex = x;
|
|
|
+ Player::BeatIndex beatIndex = x + beatDisplayOffset;
|
|
|
if(beatIndex < sequencer.beats.size() && y < sequencer.messages.size()) {
|
|
|
midi::MessageList& beat = sequencer.beats[beatIndex];
|
|
|
std::shared_ptr<midi::Message> msg_ptr = sequencer.messages[y];
|