#include "Sequencer.h" #include "ConfigurationScreen.h" #include "colors.h" #include ConfigurationScreen::ConfigurationScreen(Sequencer& seq) : parent(seq) { } void ConfigurationScreen::keyPressed(unsigned char x, unsigned char y) { std::cout << "config clicked x=" << (int)x << ", y=" << (int)y << std::endl; if(x == 8) { // very right } else if(y == 8) { // very top bool playing = sequencer.player.isPlaying(); switch(x) { case 5: disable(); sequencer.playbackScreen.enable(); break; } } else { switch(y) { case 0: { // number of beats unsigned int bit = (1 << (configWidth - x - 1)); unsigned int beatsCount = sequencer.beats.size() ^ bit; std::cout << "set number of beats to " << beatsCount << std::endl; sequencer.beats.resize(beatsCount); } break; case 1: { // sequence expansion unsigned int factor = x + 2; if(sequencer.beats.size() * factor <= maxBeatsCount) { sequencer.beats.expand(factor); sequencer.player.setBpm(std::min( sequencer.player.getBpm() * factor, maxBpm )); } } break; case 2: { // sequence reduction erasing conflicts unsigned int factor = x + 2; sequencer.beats.reduceErasingConflicts(factor); sequencer.player.setBpm(std::max( sequencer.player.getBpm() / factor, minBpm )); } break; case 4: // bpm case 5: { Player::Bpm bit = (1 << (configWidth - x - 1)); if(y == 5) { bit = (bit << configWidth); } Player::Bpm bpm = sequencer.player.getBpm() ^ bit; if(bpm >= minBpm && bpm <= maxBpm) { sequencer.player.setBpm(bpm); std::cout << "set bpm to " << sequencer.player.getBpm() << std::endl; } } break; } // sequencer.beats.print(std::cout); } refreshAll(); } void ConfigurationScreen::keyReleased(unsigned char x, unsigned char y) { refreshAll(); } void ConfigurationScreen::refresh(unsigned char x, unsigned char y) { if(x == 8) { // very right } else if(y == 8) { // very top switch(x) { case 5: setColor(x, y, colors::activeOption); break; } } else { switch(y) { case 0: { // number of beats unsigned int beatsCount = sequencer.beats.size(); if(beatsCount & (1 << (configWidth - x - 1))) { setColor(x, y, colors::activeBeatsCount); } else { setColor(x, y, colors::inactiveBeatsCount); } } break; case 1: { // sequence expansion unsigned int factor = x + 2; if(sequencer.beats.size() * factor <= maxBeatsCount) { setColor(x, y, colors::sequenceExpansionButton); } else { setColor(x, y, colors::dark); } } break; case 2: // reduce erasing conflicts setColor(x, y, colors::sequenceReductionErasingConflictsButton); break; case 4: // bpm case 5: { Player::Bpm bit = (1 << (configWidth - x - 1)); if(y == 5) { bit = (bit << configWidth); } if(sequencer.player.getBpm() & bit) { setColor(x, y, colors::activeBpmCount); } else { setColor(x, y, colors::inactiveBpmCount); } } break; } } }