keyboard selection works
This commit is contained in:
parent
8824c53dff
commit
70b03e52ca
94
src/music.c
94
src/music.c
|
@ -629,11 +629,60 @@ static void patternColRight(Music* music)
|
||||||
else nextPattern(music);
|
else nextPattern(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void resetSelection(Music* music)
|
||||||
|
{
|
||||||
|
music->tracker.select.start = (SDL_Point){-1, -1};
|
||||||
|
music->tracker.select.rect = (SDL_Rect){0, 0, 0, 0};
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkSelection(Music* music)
|
||||||
|
{
|
||||||
|
if(music->tracker.select.start.x < 0 || music->tracker.select.start.y < 0)
|
||||||
|
{
|
||||||
|
music->tracker.select.start.x = music->tracker.col;
|
||||||
|
music->tracker.select.start.y = music->tracker.row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void updateSelection(Music* music)
|
||||||
|
{
|
||||||
|
s32 rl = SDL_min(music->tracker.col, music->tracker.select.start.x);
|
||||||
|
s32 rt = SDL_min(music->tracker.row, music->tracker.select.start.y);
|
||||||
|
s32 rr = SDL_max(music->tracker.col, music->tracker.select.start.x);
|
||||||
|
s32 rb = SDL_max(music->tracker.row, music->tracker.select.start.y);
|
||||||
|
|
||||||
|
SDL_Rect* rect = &music->tracker.select.rect;
|
||||||
|
*rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1};
|
||||||
|
|
||||||
|
if(rect->x % CHANNEL_COLS + rect->w > CHANNEL_COLS)
|
||||||
|
resetSelection(music);
|
||||||
|
}
|
||||||
|
|
||||||
static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
|
static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
|
||||||
{
|
{
|
||||||
SDL_Keycode keycode = keysum->sym;
|
SDL_Keycode keycode = keysum->sym;
|
||||||
SDL_Scancode scancode = keysum->scancode;
|
SDL_Scancode scancode = keysum->scancode;
|
||||||
|
|
||||||
|
bool shift = SDL_GetModState() & KMOD_SHIFT;
|
||||||
|
|
||||||
|
if(shift)
|
||||||
|
{
|
||||||
|
switch (keycode)
|
||||||
|
{
|
||||||
|
case SDLK_UP:
|
||||||
|
case SDLK_DOWN:
|
||||||
|
case SDLK_LEFT:
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
case SDLK_HOME:
|
||||||
|
case SDLK_END:
|
||||||
|
case SDLK_PAGEUP:
|
||||||
|
case SDLK_PAGEDOWN:
|
||||||
|
case SDLK_TAB:
|
||||||
|
checkSelection(music);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else resetSelection(music);
|
||||||
|
|
||||||
switch (keycode)
|
switch (keycode)
|
||||||
{
|
{
|
||||||
case SDLK_UP: upRow(music); break;
|
case SDLK_UP: upRow(music); break;
|
||||||
|
@ -655,12 +704,29 @@ static void processTrackerKeydown(Music* music, SDL_Keysym* keysum)
|
||||||
{
|
{
|
||||||
const tic_music_pos* pos = getMusicPos(music);
|
const tic_music_pos* pos = getMusicPos(music);
|
||||||
pos->track < 0
|
pos->track < 0
|
||||||
? (SDL_GetModState() & KMOD_SHIFT ? playFrameRow(music) : playFrame(music))
|
? (shift ? playFrameRow(music) : playFrame(music))
|
||||||
: stopTrack(music);
|
: stopTrack(music);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(shift)
|
||||||
|
{
|
||||||
|
switch (keycode)
|
||||||
|
{
|
||||||
|
case SDLK_UP:
|
||||||
|
case SDLK_DOWN:
|
||||||
|
case SDLK_LEFT:
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
case SDLK_HOME:
|
||||||
|
case SDLK_END:
|
||||||
|
case SDLK_PAGEUP:
|
||||||
|
case SDLK_PAGEDOWN:
|
||||||
|
case SDLK_TAB:
|
||||||
|
updateSelection(music);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const SDL_Scancode Piano[] =
|
static const SDL_Scancode Piano[] =
|
||||||
{
|
{
|
||||||
SDL_SCANCODE_Z,
|
SDL_SCANCODE_Z,
|
||||||
|
@ -825,10 +891,22 @@ static void processPatternKeydown(Music* music, SDL_Keysym* keysum)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void selectAll(Music* music)
|
||||||
|
{
|
||||||
|
resetSelection(music);
|
||||||
|
|
||||||
|
s32 col = music->tracker.col - music->tracker.col % CHANNEL_COLS;
|
||||||
|
|
||||||
|
music->tracker.select.start = (SDL_Point){col, 0};
|
||||||
|
music->tracker.col = col + CHANNEL_COLS-1;
|
||||||
|
music->tracker.row = MUSIC_PATTERN_ROWS-1;
|
||||||
|
|
||||||
|
updateSelection(music);
|
||||||
|
}
|
||||||
|
|
||||||
static void processKeydown(Music* music, SDL_Keysym* keysum)
|
static void processKeydown(Music* music, SDL_Keysym* keysum)
|
||||||
{
|
{
|
||||||
SDL_Keycode keycode = keysum->sym;
|
SDL_Keycode keycode = keysum->sym;
|
||||||
|
@ -847,6 +925,7 @@ static void processKeydown(Music* music, SDL_Keysym* keysum)
|
||||||
{
|
{
|
||||||
switch (keycode)
|
switch (keycode)
|
||||||
{
|
{
|
||||||
|
case SDLK_a: selectAll(music); break;
|
||||||
case SDLK_z: undo(music); break;
|
case SDLK_z: undo(music); break;
|
||||||
case SDLK_y: redo(music); break;
|
case SDLK_y: redo(music); break;
|
||||||
case SDLK_UP: upFrame(music); break;
|
case SDLK_UP: upFrame(music); break;
|
||||||
|
@ -1054,17 +1133,12 @@ static void drawTrackerChannel(Music* music, s32 x, s32 y, s32 channel)
|
||||||
|
|
||||||
if(music->tracker.select.drag)
|
if(music->tracker.select.drag)
|
||||||
{
|
{
|
||||||
s32 rl = SDL_min(col, music->tracker.select.start.x);
|
updateSelection(music);
|
||||||
s32 rt = SDL_min(row, music->tracker.select.start.y);
|
|
||||||
s32 rr = SDL_max(col, music->tracker.select.start.x);
|
|
||||||
s32 rb = SDL_max(row, music->tracker.select.start.y);
|
|
||||||
|
|
||||||
music->tracker.select.rect = (SDL_Rect){rl, rt, rr - rl + 1, rb - rt + 1};
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
resetSelection(music);
|
||||||
music->tracker.select.start = (SDL_Point){col, row};
|
music->tracker.select.start = (SDL_Point){col, row};
|
||||||
music->tracker.select.rect = (SDL_Rect){0, 0, 0, 0};
|
|
||||||
|
|
||||||
music->tracker.select.drag = true;
|
music->tracker.select.drag = true;
|
||||||
}
|
}
|
||||||
|
@ -1474,4 +1548,6 @@ void initMusic(Music* music, tic_mem* tic)
|
||||||
.history = history_create(&tic->cart.sound.music, sizeof tic->cart.sound.music),
|
.history = history_create(&tic->cart.sound.music, sizeof tic->cart.sound.music),
|
||||||
.event = onStudioEvent,
|
.event = onStudioEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
resetSelection(music);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue