selection by mouse works (still no copy/paste)
This commit is contained in:
124
main.cpp
124
main.cpp
@@ -9,6 +9,12 @@
|
|||||||
#define SOUND_NUM_SAMPLES SOUND_DURATION*SAMPLES_PER_SECOND
|
#define SOUND_NUM_SAMPLES SOUND_DURATION*SAMPLES_PER_SECOND
|
||||||
#define SOUND_SIZE_IN_BYTES SOUND_NUM_SAMPLES*AUDIO_FORMAT_SIZE
|
#define SOUND_SIZE_IN_BYTES SOUND_NUM_SAMPLES*AUDIO_FORMAT_SIZE
|
||||||
|
|
||||||
|
struct selection_t {
|
||||||
|
int channel = 0;
|
||||||
|
int row = 0;
|
||||||
|
int part = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/*#define get_note(x) (x>>10)
|
/*#define get_note(x) (x>>10)
|
||||||
#define get_instrument(x) ((x>>8) & 0x3)
|
#define get_instrument(x) ((x>>8) & 0x3)
|
||||||
#define get_volume(x) ((x>>4) & 0xF)
|
#define get_volume(x) ((x>>4) & 0xF)
|
||||||
@@ -19,13 +25,7 @@ char note_names[12][3] = { "C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#",
|
|||||||
Song song;
|
Song song;
|
||||||
bool muted[4] = { false, false, false, false };
|
bool muted[4] = { false, false, false, false };
|
||||||
|
|
||||||
int selected_channel = 0;
|
selection_t sel_start, sel_end;
|
||||||
int selected_row = 0;
|
|
||||||
int selected_part = 0;
|
|
||||||
|
|
||||||
int selected_channel_end = -1;
|
|
||||||
int selected_row_end = -1;
|
|
||||||
int selected_part_end = -1;
|
|
||||||
|
|
||||||
int scroll = 0;
|
int scroll = 0;
|
||||||
int base_octave = 4;
|
int base_octave = 4;
|
||||||
@@ -148,21 +148,22 @@ int main(int argc, char* argv[]) {
|
|||||||
if (sdlEvent.type == SDL_MOUSEBUTTONDOWN) {
|
if (sdlEvent.type == SDL_MOUSEBUTTONDOWN) {
|
||||||
if (sdlEvent.button.button == SDL_BUTTON_LEFT) {
|
if (sdlEvent.button.button == SDL_BUTTON_LEFT) {
|
||||||
if ((sdlEvent.button.x >= 13) && (sdlEvent.button.x <= 149) && (sdlEvent.button.y >= 14) && (sdlEvent.button.y <= 239) ) {
|
if ((sdlEvent.button.x >= 13) && (sdlEvent.button.x <= 149) && (sdlEvent.button.y >= 14) && (sdlEvent.button.y <= 239) ) {
|
||||||
selected_channel_end = -1;
|
//selected_channel_end = -1;
|
||||||
selected_row = scroll + int((sdlEvent.button.y-14)/7);
|
sel_start.channel = (sdlEvent.button.x-13)/35;
|
||||||
selected_channel = (sdlEvent.button.x-13)/35;
|
sel_start.row = scroll + int((sdlEvent.button.y-14)/7);
|
||||||
int part_pos = (sdlEvent.button.x-13)-(selected_channel*35);
|
int part_pos = (sdlEvent.button.x-13)-(sel_start.channel*35);
|
||||||
if (part_pos <= 10) {
|
if (part_pos <= 10) {
|
||||||
selected_part = 0;
|
sel_start.part = 0;
|
||||||
} else if (part_pos <= 15) {
|
} else if (part_pos <= 15) {
|
||||||
selected_part = 1;
|
sel_start.part = 1;
|
||||||
} else if (part_pos <= 21) {
|
} else if (part_pos <= 21) {
|
||||||
selected_part = 2;
|
sel_start.part = 2;
|
||||||
} else if (part_pos <= 26) {
|
} else if (part_pos <= 26) {
|
||||||
selected_part = 3;
|
sel_start.part = 3;
|
||||||
} else if (part_pos <= 31) {
|
} else if (part_pos <= 31) {
|
||||||
selected_part = 4;
|
sel_start.part = 4;
|
||||||
}
|
}
|
||||||
|
sel_end = sel_start;
|
||||||
}
|
}
|
||||||
for (int i=0; i<4; ++i) {
|
for (int i=0; i<4; ++i) {
|
||||||
if ((sdlEvent.button.x >= 12+i*35) && (sdlEvent.button.x <= 45+i*35) && (sdlEvent.button.y >= 2) && (sdlEvent.button.y <= 13) ) {
|
if ((sdlEvent.button.x >= 12+i*35) && (sdlEvent.button.x <= 45+i*35) && (sdlEvent.button.y >= 2) && (sdlEvent.button.y <= 13) ) {
|
||||||
@@ -172,6 +173,26 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sdlEvent.type == SDL_MOUSEMOTION) {
|
||||||
|
if (sdlEvent.motion.state & SDL_BUTTON_LMASK != 0) {
|
||||||
|
if ((sdlEvent.motion.x >= 13) && (sdlEvent.motion.x <= 149) && (sdlEvent.motion.y >= 14) && (sdlEvent.motion.y <= 239) ) {
|
||||||
|
sel_end.channel = (sdlEvent.motion.x-13)/35;
|
||||||
|
sel_end.row = scroll + int((sdlEvent.motion.y-14)/7);
|
||||||
|
int part_pos = (sdlEvent.motion.x-13)-(sel_end.channel*35);
|
||||||
|
if (part_pos <= 10) {
|
||||||
|
sel_end.part = 0;
|
||||||
|
} else if (part_pos <= 15) {
|
||||||
|
sel_end.part = 1;
|
||||||
|
} else if (part_pos <= 21) {
|
||||||
|
sel_end.part = 2;
|
||||||
|
} else if (part_pos <= 26) {
|
||||||
|
sel_end.part = 3;
|
||||||
|
} else if (part_pos <= 31) {
|
||||||
|
sel_end.part = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (sdlEvent.type == SDL_MOUSEWHEEL) {
|
if (sdlEvent.type == SDL_MOUSEWHEEL) {
|
||||||
scroll -= sdlEvent.wheel.y*4;
|
scroll -= sdlEvent.wheel.y*4;
|
||||||
if (scroll < 0) scroll = 0; else if (scroll > 32) scroll = 32;
|
if (scroll < 0) scroll = 0; else if (scroll > 32) scroll = 32;
|
||||||
@@ -179,46 +200,45 @@ int main(int argc, char* argv[]) {
|
|||||||
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 < 63) selected_row++;
|
if (sel_start.row < 63) sel_start.row++;
|
||||||
if (selected_row >= 32 + scroll) scroll = selected_row-31;
|
if (sel_start.row >= 32 + scroll) scroll = sel_start.row-31;
|
||||||
|
sel_end = sel_start;
|
||||||
} else if (key == SDL_SCANCODE_UP) {
|
} else if (key == SDL_SCANCODE_UP) {
|
||||||
if (selected_row > 0) selected_row--;
|
if (sel_start.row > 0) sel_start.row--;
|
||||||
if (selected_row < scroll) scroll = selected_row;
|
if (sel_start.row < scroll) scroll = sel_start.row;
|
||||||
|
sel_end = sel_start;
|
||||||
} else if (key == SDL_SCANCODE_LEFT) {
|
} else if (key == SDL_SCANCODE_LEFT) {
|
||||||
if (selected_channel > 0 || selected_part > 0) {
|
if (sel_start.channel > 0 || sel_start.part > 0) {
|
||||||
if (selected_part > 0) {
|
if (sel_start.part > 0) {
|
||||||
selected_part--;
|
sel_start.part--;
|
||||||
} else {
|
} else {
|
||||||
selected_channel--;
|
sel_start.channel--;
|
||||||
selected_part = 4;
|
sel_start.part = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sel_end = sel_start;
|
||||||
} else if (key == SDL_SCANCODE_RIGHT) {
|
} else if (key == SDL_SCANCODE_RIGHT) {
|
||||||
if (selected_channel < 3 || selected_part < 4) {
|
if (sel_start.channel < 3 || sel_start.part < 4) {
|
||||||
if (selected_part < 4) {
|
if (sel_start.part < 4) {
|
||||||
selected_part++;
|
sel_start.part++;
|
||||||
} else {
|
} else {
|
||||||
selected_channel++;
|
sel_start.channel++;
|
||||||
selected_part = 0;
|
sel_start.part = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sel_end = sel_start;
|
||||||
}
|
}
|
||||||
Note note(song.GetCurrentNote(selected_channel, selected_row));
|
Note note(song.GetCurrentNote(sel_start.channel, sel_start.row));
|
||||||
//uint8_t base_note = 1+(base_octave-2)*12;
|
//uint8_t base_note = 1+(base_octave-2)*12;
|
||||||
if ((key == SDL_SCANCODE_PERIOD) || (key == SDL_SCANCODE_DELETE)) note.Set(0);
|
if ((key == SDL_SCANCODE_PERIOD) || (key == SDL_SCANCODE_DELETE)) note.Set(0);
|
||||||
if (key == SDL_SCANCODE_RETURN) copied_note = note.Get();
|
if (key == SDL_SCANCODE_RETURN) copied_note = note.Get();
|
||||||
if (key == SDL_SCANCODE_SPACE) {
|
if (key == SDL_SCANCODE_SPACE) {
|
||||||
note.Set(copied_note);
|
note.Set(copied_note);
|
||||||
playNote(note);
|
playNote(note);
|
||||||
/*channel[0].setup(note.Get());
|
|
||||||
channel[1].setup(0);
|
|
||||||
channel[2].setup(0);
|
|
||||||
channel[3].setup(0);
|
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);*/
|
|
||||||
}
|
}
|
||||||
if (key == SDL_SCANCODE_F4) {
|
if (key == SDL_SCANCODE_F4) {
|
||||||
for (int i=0;i<4;++i) {
|
for (int i=0;i<4;++i) {
|
||||||
channel[i].setup(song.GetCurrentNote(i, selected_row));
|
channel[i].setup(song.GetCurrentNote(i, sel_start.row));
|
||||||
channel[i].setMute(muted[i]);
|
channel[i].setMute(muted[i]);
|
||||||
}
|
}
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||||
@@ -234,7 +254,7 @@ int main(int argc, char* argv[]) {
|
|||||||
if (key == SDL_SCANCODE_F8) {
|
if (key == SDL_SCANCODE_F8) {
|
||||||
song.Stop();
|
song.Stop();
|
||||||
}
|
}
|
||||||
if (selected_part==0) {
|
if (sel_start.part==0) {
|
||||||
bool m = true;
|
bool m = true;
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case SDL_SCANCODE_Z: note.SetFirstNote(0, base_octave, current_instrument, current_volume, current_effect); break;
|
case SDL_SCANCODE_Z: note.SetFirstNote(0, base_octave, current_instrument, current_volume, current_effect); break;
|
||||||
@@ -261,7 +281,7 @@ int main(int argc, char* argv[]) {
|
|||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);*/
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selected_part==1) {
|
if (sel_start.part==1) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case SDL_SCANCODE_2: note.SetOctave(2); playNote(note); break;
|
case SDL_SCANCODE_2: note.SetOctave(2); playNote(note); break;
|
||||||
case SDL_SCANCODE_3: note.SetOctave(3); playNote(note); break;
|
case SDL_SCANCODE_3: note.SetOctave(3); playNote(note); break;
|
||||||
@@ -271,7 +291,7 @@ int main(int argc, char* argv[]) {
|
|||||||
default: break;
|
default: break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (selected_part==2) {
|
if (sel_start.part==2) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case SDL_SCANCODE_0: note.SetInstrument(0); playNote(note); break;
|
case SDL_SCANCODE_0: note.SetInstrument(0); playNote(note); break;
|
||||||
case SDL_SCANCODE_1: note.SetInstrument(1); playNote(note); break;
|
case SDL_SCANCODE_1: note.SetInstrument(1); playNote(note); break;
|
||||||
@@ -280,7 +300,7 @@ int main(int argc, char* argv[]) {
|
|||||||
default: break;
|
default: break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (selected_part==3) {
|
if (sel_start.part==3) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case SDL_SCANCODE_0: note.SetVolume(0); playNote(note); break;
|
case SDL_SCANCODE_0: note.SetVolume(0); playNote(note); break;
|
||||||
case SDL_SCANCODE_1: note.SetVolume(1); playNote(note); break;
|
case SDL_SCANCODE_1: note.SetVolume(1); playNote(note); break;
|
||||||
@@ -301,7 +321,7 @@ int main(int argc, char* argv[]) {
|
|||||||
default: break;
|
default: break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (selected_part==4) {
|
if (sel_start.part==4) {
|
||||||
switch(key) {
|
switch(key) {
|
||||||
case SDL_SCANCODE_0: note.SetEffect(0); playNote(note); break;
|
case SDL_SCANCODE_0: note.SetEffect(0); playNote(note); break;
|
||||||
case SDL_SCANCODE_1: note.SetEffect(1); playNote(note); break;
|
case SDL_SCANCODE_1: note.SetEffect(1); playNote(note); break;
|
||||||
@@ -322,7 +342,7 @@ int main(int argc, char* argv[]) {
|
|||||||
default: break;
|
default: break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
song.SetCurrentNote(selected_channel, selected_row, note.Get());
|
song.SetCurrentNote(sel_start.channel, sel_start.row, note.Get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
draw_clear(color_dark_grey);
|
draw_clear(color_dark_grey);
|
||||||
@@ -345,21 +365,23 @@ int main(int argc, char* argv[]) {
|
|||||||
for (int y=0; y<32; ++y) {
|
for (int y=0; y<32; ++y) {
|
||||||
if ((song.IsPlaying()) && (y+scroll == song.GetCurrentRow())) {
|
if ((song.IsPlaying()) && (y+scroll == song.GetCurrentRow())) {
|
||||||
draw_fill(xp-1, yp-1, 32, 7, color_yellow);
|
draw_fill(xp-1, yp-1, 32, 7, color_yellow);
|
||||||
} else if (x == selected_channel && (y+scroll) == selected_row) {
|
} else if (x >= sel_start.channel && x <= sel_end.channel && (y+scroll) >= sel_start.row && (y+scroll) <= sel_end.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) {
|
if (x == sel_start.channel && (y+scroll) == sel_start.row) {
|
||||||
case 0: draw_fill(xp-1, yp-1, 11, 7, color_yellow); break;
|
switch (sel_start.part) {
|
||||||
case 1: draw_fill(9+xp, yp-1, 6, 7, color_yellow); break;
|
case 0: draw_fill(xp-1, yp-1, 11, 7, color_yellow); break;
|
||||||
case 2: draw_fill(15+xp, yp-1, 6, 7, color_yellow); break;
|
case 1: draw_fill(9+xp, yp-1, 6, 7, color_yellow); break;
|
||||||
case 3: draw_fill(20+xp, yp-1, 6, 7, color_yellow); break;
|
case 2: draw_fill(15+xp, yp-1, 6, 7, color_yellow); break;
|
||||||
case 4: draw_fill(25+xp, yp-1, 6, 7, color_yellow); break;
|
case 3: draw_fill(20+xp, yp-1, 6, 7, color_yellow); break;
|
||||||
|
case 4: draw_fill(25+xp, yp-1, 6, 7, color_yellow); break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Note note(song.GetCurrentNote(x, y+scroll));
|
Note note(song.GetCurrentNote(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+scroll) == selected_row) color = color_dark_purple;
|
if (x >= sel_start.channel && x <= sel_end.channel && (y+scroll) >= sel_start.row && (y+scroll) <= sel_end.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 if (note.GetAbsoluteNote() == 63) {
|
} else if (note.GetAbsoluteNote() == 63) {
|
||||||
|
|||||||
Reference in New Issue
Block a user