Skip to content

Commit

Permalink
Wavetable copypaste, togglable drag selection
Browse files Browse the repository at this point in the history
  • Loading branch information
LTVA1 committed Oct 28, 2022
1 parent f95a983 commit dddea70
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 219 deletions.
Binary file added examples/songs/LTVA-examples/CSM_timer_PWM_demo.kt
Binary file not shown.
2 changes: 1 addition & 1 deletion klystron
4 changes: 4 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ static const struct { int type; const char *name; void *param; Uint64 mask; } co
{ C_BOOL, "show_bpm_count", &mused.flags2, SHOW_BPM }, //wasn't there
{ C_BOOL, "smooth_scroll", &mused.flags2, SMOOTH_SCROLL },
{ C_BOOL, "highlight_commands", &mused.flags2, HIGHLIGHT_COMMANDS },
{ C_BOOL, "drag_selection_pattern", &mused.flags2, DRAG_SELECT_PATTERN },
{ C_BOOL, "drag_selection_sequence", &mused.flags2, DRAG_SELECT_SEQUENCE },
{ C_BOOL, "drag_selection_inst_program", &mused.flags2, DRAG_SELECT_PROGRAM },
{ C_BOOL, "drag_selection_4op_program", &mused.flags2, DRAG_SELECT_4OP },
{ C_END }
};

Expand Down
45 changes: 24 additions & 21 deletions src/copypaste.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,31 +492,34 @@ void paste()

else
{
if(mused.selection.prev_name_index != mused.selected_wavetable)
if(mused.cp.type == CP_WAVETABLE)
{
if(mused.mus.cyd->wavetable_entries[mused.selected_wavetable].data)
if(mused.selection.prev_name_index != mused.selected_wavetable)
{
free(mused.mus.cyd->wavetable_entries[mused.selected_wavetable].data);
}

cp_paste_items(&mused.cp, CP_WAVETABLE, &mused.mus.cyd->wavetable_entries[mused.selected_wavetable], 1, sizeof(mused.mus.cyd->wavetable_entries[mused.selected_wavetable]));

memset(mused.song.wavetable_names[mused.selected_wavetable], 0, MUS_WAVETABLE_NAME_LEN + 1);

memcpy(mused.song.wavetable_names[mused.selected_wavetable], mused.song.wavetable_names[mused.selection.prev_name_index], MUS_WAVETABLE_NAME_LEN + 1);

CydWavetableEntry *wave = &mused.mus.cyd->wavetable_entries[mused.selected_wavetable];

Sint16* old_data = wave->data;

if(old_data)
{
wave->data = calloc(wave->samples, sizeof(Sint16));
if(mused.mus.cyd->wavetable_entries[mused.selected_wavetable].data)
{
free(mused.mus.cyd->wavetable_entries[mused.selected_wavetable].data);
}

memcpy(wave->data, old_data, wave->samples * sizeof(Sint16));
cp_paste_items(&mused.cp, CP_WAVETABLE, &mused.mus.cyd->wavetable_entries[mused.selected_wavetable], 1, sizeof(mused.mus.cyd->wavetable_entries[mused.selected_wavetable]));

memset(mused.song.wavetable_names[mused.selected_wavetable], 0, MUS_WAVETABLE_NAME_LEN + 1);

memcpy(mused.song.wavetable_names[mused.selected_wavetable], mused.song.wavetable_names[mused.selection.prev_name_index], MUS_WAVETABLE_NAME_LEN + 1);

CydWavetableEntry *wave = &mused.mus.cyd->wavetable_entries[mused.selected_wavetable];

Sint16* old_data = wave->data;

if(old_data)
{
wave->data = calloc(wave->samples, sizeof(Sint16));

memcpy(wave->data, old_data, wave->samples * sizeof(Sint16));
}

mused.wavetable_preview_idx = 0xff;
}

mused.wavetable_preview_idx = 0xff;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ static void play_the_jams(int sym, int chn, int state)
{
if (chn == -1 && !(mused.flags & MULTICHANNEL_PREVIEW))
chn = 0;

int c = mus_trigger_instrument(&mused.mus, chn, &mused.song.instrument[mused.current_instrument], note << 8, CYD_PAN_CENTER);

mused.cyd.channel[c].subosc[0].wave.acc = 0;
Expand Down
15 changes: 13 additions & 2 deletions src/menudefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Menu oversamplemenu[] =
{ 0, prefsmenu, "2x", NULL, change_oversample, (void*)1, 0, 0 },
{ 0, prefsmenu, "4x", NULL, change_oversample, (void*)2, 0, 0 },
{ 0, prefsmenu, "8x", NULL, change_oversample, (void*)3, 0, 0 },
{ 0, NULL,NULL },
{ 0, NULL, NULL },
};


Expand All @@ -122,7 +122,16 @@ Menu patternlengthmenu[] =
{ 0, prefsmenu, "32 steps", NULL, change_default_pattern_length, (void*)32, 0, 0 },
{ 0, prefsmenu, "48 steps", NULL, change_default_pattern_length, (void*)48, 0, 0 },
{ 0, prefsmenu, "64 steps", NULL, change_default_pattern_length, (void*)64, 0, 0 },
{ 0, NULL,NULL },
{ 0, NULL, NULL },
};

Menu drag_selection_menu[] =
{
{ 0, prefsmenu, "Pattern editor", NULL, MENU_CHECK, &mused.flags2, (void*)DRAG_SELECT_PATTERN, 0 },
{ 0, prefsmenu, "Sequence editor", NULL, MENU_CHECK, &mused.flags2, (void*)DRAG_SELECT_SEQUENCE, 0 },
{ 0, prefsmenu, "Inst. prog. editor", NULL, MENU_CHECK, &mused.flags2, (void*)DRAG_SELECT_PROGRAM, 0 },
{ 0, prefsmenu, "4-OP prog. editor", NULL, MENU_CHECK, &mused.flags2, (void*)DRAG_SELECT_4OP, 0 },
{ 0, NULL, NULL },
};


Expand Down Expand Up @@ -160,6 +169,8 @@ const Menu prefsmenu[] =
{ 0, mainmenu, "Load default song on startup", NULL, MENU_CHECK, &mused.flags, (void*)START_WITH_TEMPLATE, 0 },
{ 0, mainmenu, "Use system mouse cursor", NULL, MENU_CHECK_NOSET, &mused.flags, (void*)USE_SYSTEM_CURSOR, toggle_mouse_cursor },
{ 0, mainmenu, "Smooth pattern scroll", NULL, MENU_CHECK, &mused.flags2, (void*)SMOOTH_SCROLL, 0 },
{ 0, mainmenu, "", NULL, NULL },
{ 0, mainmenu, "Mouse drag selection", drag_selection_menu },
{ 0, NULL, NULL }
};

Expand Down
5 changes: 5 additions & 0 deletions src/mused.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ enum
SMOOTH_SCROLL = 16,
SHOW_FLATS_INSTEAD_OF_SHARPS = 32,
HIGHLIGHT_COMMANDS = 64,

DRAG_SELECT_PATTERN = 128,
DRAG_SELECT_SEQUENCE = 256,
DRAG_SELECT_PROGRAM = 512,
DRAG_SELECT_4OP = 1024,
};

//#define SHOW_OSCILLOSCOPES_PATTERN_EDITOR ((Uint64)65536 << 16)
Expand Down
Loading

0 comments on commit dddea70

Please sign in to comment.