more keyboard interact. mouse interact

This commit is contained in:
2021-09-05 23:23:01 +02:00
parent dda58872ad
commit e0b3720126
3 changed files with 66 additions and 22 deletions

View File

@@ -21,6 +21,9 @@ int selected_row = 0;
int selected_part = 0; int selected_part = 0;
int scroll = 0; int scroll = 0;
int base_octave = 4; int base_octave = 4;
int current_instrument = 0;
int current_volume = 2;
int current_effect = 0;
SDL_AudioSpec audioSpec{SAMPLES_PER_SECOND, AUDIO_FORMAT, 1, 0, 512, 0, 0, NULL, NULL}; SDL_AudioSpec audioSpec{SAMPLES_PER_SECOND, AUDIO_FORMAT, 1, 0, 512, 0, 0, NULL, NULL};
@@ -86,12 +89,38 @@ int main(int argc, char* argv[]) {
while (!exit) { while (!exit) {
while (SDL_PollEvent(&sdlEvent)) { while (SDL_PollEvent(&sdlEvent)) {
if (sdlEvent.type == SDL_QUIT) { exit = true; break;} if (sdlEvent.type == SDL_QUIT) { exit = true; break;}
if (sdlEvent.type == SDL_MOUSEBUTTONDOWN) {
if (sdlEvent.button.button == SDL_BUTTON_LEFT) {
if ((sdlEvent.button.x >= 3) && (sdlEvent.button.x <= 139) && (sdlEvent.button.y >= 14) && (sdlEvent.button.y <= 239) ) {
selected_row = scroll + int((sdlEvent.button.y-14)/7);
selected_channel = (sdlEvent.button.x-3)/35;
int part_pos = (sdlEvent.button.x-3)-(selected_channel*35);
if (part_pos <= 10) {
selected_part = 0;
} else if (part_pos <= 15) {
selected_part = 1;
} else if (part_pos <= 21) {
selected_part = 2;
} else if (part_pos <= 26) {
selected_part = 3;
} else if (part_pos <= 31) {
selected_part = 4;
}
}
}
}
if (sdlEvent.type == SDL_MOUSEWHEEL) {
scroll -= sdlEvent.wheel.y;
if (scroll < 0) scroll = 0; else if (scroll > 32) scroll = 32;
}
if (sdlEvent.type == SDL_KEYDOWN) { if (sdlEvent.type == SDL_KEYDOWN) {
SDL_Scancode key = sdlEvent.key.keysym.scancode; SDL_Scancode key = sdlEvent.key.keysym.scancode;
if (key == SDL_SCANCODE_DOWN) { if (key == SDL_SCANCODE_DOWN) {
if (selected_row < 32) selected_row++; if (selected_row < 63) selected_row++;
if (selected_row >= 32 + scroll) scroll = selected_row-31;
} else if (key == SDL_SCANCODE_UP) { } else if (key == SDL_SCANCODE_UP) {
if (selected_row > 0) selected_row--; if (selected_row > 0) selected_row--;
if (selected_row < scroll) scroll = selected_row;
} else if (key == SDL_SCANCODE_LEFT) { } else if (key == SDL_SCANCODE_LEFT) {
if (selected_channel > 0 || selected_part > 0) { if (selected_channel > 0 || selected_part > 0) {
if (selected_part > 0) { if (selected_part > 0) {
@@ -113,22 +142,28 @@ int main(int argc, char* argv[]) {
} }
Note note(pattern[selected_channel][selected_row]); Note note(pattern[selected_channel][selected_row]);
//uint8_t base_note = 1+(base_octave-2)*12; //uint8_t base_note = 1+(base_octave-2)*12;
if (key == SDL_SCANCODE_PERIOD) note.Set(0); if ((key == SDL_SCANCODE_PERIOD) || (key == SDL_SCANCODE_DELETE)) note.Set(0);
if (key == SDL_SCANCODE_SPACE) {
tonegen.setup(note.Get());
numSamples = tonegen.getSamples(SOUND_NUM_SAMPLES, beeps);
SDL_QueueAudio(sdlAudioDevice, &beeps[0], SOUND_SIZE_IN_BYTES);
SDL_PauseAudioDevice(sdlAudioDevice, 0);
}
if (selected_part==0) { if (selected_part==0) {
bool m = true; bool m = true;
switch(key) { switch(key) {
case SDL_SCANCODE_Z: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(0); break; case SDL_SCANCODE_Z: note.SetFirstNote(0, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_S: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(1); break; case SDL_SCANCODE_S: note.SetFirstNote(1, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_X: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(2); break; case SDL_SCANCODE_X: note.SetFirstNote(2, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_D: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(3); break; case SDL_SCANCODE_D: note.SetFirstNote(3, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_C: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(4); break; case SDL_SCANCODE_C: note.SetFirstNote(4, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_V: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(5); break; case SDL_SCANCODE_V: note.SetFirstNote(5, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_G: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(6); break; case SDL_SCANCODE_G: note.SetFirstNote(6, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_B: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(7); break; case SDL_SCANCODE_B: note.SetFirstNote(7, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_H: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(8); break; case SDL_SCANCODE_H: note.SetFirstNote(8, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_N: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(9); break; case SDL_SCANCODE_N: note.SetFirstNote(9, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_J: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(10); break; case SDL_SCANCODE_J: note.SetFirstNote(10, base_octave, current_instrument, current_volume, current_effect); break;
case SDL_SCANCODE_M: if (note.GetNote()==0) note.SetOctave(base_octave); note.SetNote(11); break; case SDL_SCANCODE_M: note.SetFirstNote(11, base_octave, current_instrument, current_volume, current_effect); break;
default: m = false; break; default: m = false; break;
}; };
if (m) { if (m) {
@@ -217,7 +252,7 @@ int main(int argc, char* argv[]) {
for (int x=0; x<4; ++x) { for (int x=0; x<4; ++x) {
yp = 15; yp = 15;
for (int y=0; y<32; ++y) { for (int y=0; y<32; ++y) {
if (x == selected_channel && y == selected_row) { if (x == selected_channel && (y+scroll) == selected_row) {
draw_fill(xp-1, yp-1, 32, 7, color_dark_blue); draw_fill(xp-1, yp-1, 32, 7, color_dark_blue);
switch (selected_part) { switch (selected_part) {
case 0: draw_fill(xp-1, yp-1, 11, 7, color_yellow); break; case 0: draw_fill(xp-1, yp-1, 11, 7, color_yellow); break;
@@ -227,11 +262,11 @@ int main(int argc, char* argv[]) {
case 4: draw_fill(25+xp, yp-1, 6, 7, color_yellow); break; case 4: draw_fill(25+xp, yp-1, 6, 7, color_yellow); break;
} }
} }
Note note(pattern[x][y]); Note note(pattern[x][y+scroll]);
//Uint16 current_note = pattern[x][y]; //Uint16 current_note = pattern[x][y];
if (note.GetAbsoluteNote() == 0) { if (note.GetAbsoluteNote() == 0) {
uint8_t color = color_dark_blue; uint8_t color = color_dark_blue;
if (x == selected_channel && y == selected_row) color = color_dark_purple; if (x == selected_channel && (y+scroll) == selected_row) color = color_dark_purple;
draw_string("...", xp, yp, color); draw_string("...", xp, yp, color);
draw_string("...", 16+xp, yp, color); draw_string("...", 16+xp, yp, color);
} else { } else {
@@ -243,11 +278,8 @@ int main(int argc, char* argv[]) {
draw_char(get_hex(note.GetVolume()), 21+xp, yp, color_blue); draw_char(get_hex(note.GetVolume()), 21+xp, yp, color_blue);
draw_char(get_hex(note.GetEffect()), 26+xp, yp, color_lavender); draw_char(get_hex(note.GetEffect()), 26+xp, yp, color_lavender);
} }
if ((y!=0) && (((y+scroll)%8)==0)) draw_dotted(xp, yp, xp+30, color_lavender);
yp += 7; yp += 7;
if ((y%8)==7) {
draw_dotted(xp, yp, xp+30, color_lavender);
//yp++;
}
} }
xp += 35; xp += 35;
} }

View File

@@ -8,7 +8,8 @@ const uint8_t get_note_from_wholenote(const uint8_t wholenote) {
} }
Note::Note() { Note::Note() {
note = octave = instrument = volume = effect = 0; note = octave = instrument = effect = 0;
volume = 2;
} }
Note::Note(const uint16_t note) { Note::Note(const uint16_t note) {
@@ -53,6 +54,16 @@ void Note::SetNote(const uint8_t note) {
this->note = note; this->note = note;
} }
void Note::SetFirstNote(const uint8_t note, const uint8_t octave, const uint8_t instrument, const uint8_t volume, const uint8_t effect) {
if (GetAbsoluteNote() == 0) {
this->octave = octave;
this->instrument = instrument;
this->volume = volume;
this->effect = effect;
}
this->note = note;
}
void Note::SetOctave(const uint8_t octave) { void Note::SetOctave(const uint8_t octave) {
this->octave = octave; this->octave = octave;
} }

1
note.h
View File

@@ -12,6 +12,7 @@ class Note {
void Set(const uint16_t note); void Set(const uint16_t note);
void SetAbsoluteNote(const uint8_t note); void SetAbsoluteNote(const uint8_t note);
void SetNote(const uint8_t note); void SetNote(const uint8_t note);
void SetFirstNote(const uint8_t note, const uint8_t octave, const uint8_t instrument, const uint8_t volume, const uint8_t effect);
void SetOctave(const uint8_t octave); void SetOctave(const uint8_t octave);
void SetInstrument(const uint8_t instrument); void SetInstrument(const uint8_t instrument);
void SetVolume(const uint8_t volume); void SetVolume(const uint8_t volume);