this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

left/right mouse click or +- numpad to inc/dec values in the music editor #323

nesbox 009ba3a1 8d877eff

+129 -34
+1
src/defines.h
··· 29 29 #define MAX3(a,b,c) MAX(MAX(a, b), c) 30 30 #define CLAMP(v,a,b) (MIN(MAX(v,a),b)) 31 31 #define SWAP(a, b, type) do { type temp = a; a = b; b = temp; } while (0) 32 + #define MEMCMP(a, b) (sizeof a == sizeof b && memcmp(&a, &b, sizeof a) == 0) 32 33 #define ZEROMEM(p) memset(&p, 0, sizeof p) 33 34 #define MOVE(...) memmove(malloc(sizeof __VA_ARGS__), &__VA_ARGS__, sizeof __VA_ARGS__) 34 35 #define DEF2STR2(x) #x
+127 -33
src/studio/editors/music.c
··· 85 85 tic_api_rect(tic, x, y, w, h, tic_color_black); 86 86 } 87 87 88 + static void setChannelPattern(Music* music, s32 delta, s32 channel); 89 + 90 + static s32 getStep(Music* music) 91 + { 92 + enum{DefaultStep = 1, ExtraStep = 10}; 93 + 94 + return tic_api_key(music->tic, tic_key_shift) ? ExtraStep : DefaultStep; 95 + } 96 + 88 97 static void drawEditbox(Music* music, s32 x, s32 y, s32 value, void(*set)(Music*, s32, s32 channel), s32 channel) 89 98 { 90 99 tic_mem* tic = music->tic; ··· 119 128 120 129 showTooltip(music->studio, "select pattern ID"); 121 130 122 - if (checkMouseClick(music->studio, &rect, tic_mouse_left)) 131 + bool left = checkMouseClick(music->studio, &rect, tic_mouse_left); 132 + if(left || checkMouseClick(music->studio, &rect, tic_mouse_right)) 123 133 { 124 - music->tracker.edit.y = -1; 125 - music->tracker.edit.x = channel * CHANNEL_COLS; 134 + tic_point pos = {channel * CHANNEL_COLS, -1}; 126 135 127 - s32 mx = tic_api_mouse(tic).x - rect.x; 128 - music->tracker.col = mx / TIC_FONT_WIDTH ? 1 : 0; 136 + if(MEMCMP(music->tracker.edit, pos)) 137 + { 138 + s32 step = getStep(music); 139 + setChannelPattern(music, left ? +step : -step, channel); 140 + } 141 + else 142 + { 143 + music->tracker.edit = pos; 144 + s32 mx = tic_api_mouse(tic).x - rect.x; 145 + music->tracker.col = mx / TIC_FONT_WIDTH ? 1 : 0; 146 + } 129 147 } 130 148 } 131 149 ··· 166 184 static inline s32 switchWidth(s32 value) 167 185 { 168 186 return value > 99 ? 3 * TIC_FONT_WIDTH : 2 * TIC_FONT_WIDTH; 169 - } 170 - 171 - static s32 getStep(Music* music) 172 - { 173 - enum{DefaultStep = 1, ExtraStep = 5}; 174 - 175 - return tic_api_key(music->tic, tic_key_shift) ? ExtraStep : DefaultStep; 176 187 } 177 188 178 189 static void drawSwitch(Music* music, s32 x, s32 y, const char* label, s32 value, void(*set)(Music*, s32)) ··· 231 242 music->drag.x = tic_api_mouse(tic).x; 232 243 music->drag.start = value; 233 244 } 245 + } 246 + 247 + bool left = checkMouseClick(music->studio, &rect, tic_mouse_left); 248 + if(left || checkMouseClick(music->studio, &rect, tic_mouse_right)) 249 + { 250 + s32 step = getStep(music); 251 + set(music, value + (left ? +step : -step)); 234 252 } 235 253 } 236 254 ··· 1259 1277 } 1260 1278 } 1261 1279 } 1280 + 1281 + switch (getKeyboardText(music->studio)) 1282 + { 1283 + case '+': setChannelPattern(music, +1, music->tracker.edit.x / CHANNEL_COLS); break; 1284 + case '-': setChannelPattern(music, -1, music->tracker.edit.x / CHANNEL_COLS); break; 1285 + } 1262 1286 } 1263 1287 1264 1288 static void updatePianoEditPos(Music* music) ··· 1333 1357 s32 col = music->piano.edit.x / 2; 1334 1358 s32 dec = sym2dec(sym); 1335 1359 s32 hex = sym2hex(sym); 1360 + s32 delta = sym == '+' ? +1 : -1; 1361 + 1336 1362 tic_track_row* row = getPianoRow(music); 1337 1363 1338 1364 switch(col) ··· 1341 1367 case PianoChannel2Column: 1342 1368 case PianoChannel3Column: 1343 1369 case PianoChannel4Column: 1370 + switch (sym) 1371 + { 1372 + case '+': 1373 + case '-': 1374 + setChannelPattern(music, delta, music->piano.edit.x / 2); 1375 + break; 1376 + } 1377 + 1344 1378 if(dec >= 0) 1345 1379 { 1346 1380 s32 pattern = setDigit(1 - music->piano.edit.x & 1, ··· 1354 1388 } 1355 1389 break; 1356 1390 case PianoSfxColumn: 1357 - if(row && row->note >= NoteStart && dec >= 0) 1391 + if(row && row->note >= NoteStart) 1358 1392 { 1359 - s32 sfx = setDigit(1 - music->piano.edit.x & 1, tic_tool_get_track_row_sfx(row), dec); 1360 - tic_tool_set_track_row_sfx(row, sfx); 1361 - history_add(music->history); 1393 + switch (sym) 1394 + { 1395 + case '+': 1396 + case '-': 1397 + tic_tool_set_track_row_sfx(row, tic_modulo(tic_tool_get_track_row_sfx(row) + delta, SFX_COUNT)); 1398 + break; 1399 + default: 1400 + if(dec >= 0) 1401 + { 1402 + s32 sfx = setDigit(1 - music->piano.edit.x & 1, tic_tool_get_track_row_sfx(row), dec); 1403 + tic_tool_set_track_row_sfx(row, sfx); 1404 + updatePianoEditCol(music); 1405 + } 1406 + } 1362 1407 1408 + history_add(music->history); 1363 1409 music->last.sfx = tic_tool_get_track_row_sfx(row); 1364 - 1365 - updatePianoEditCol(music); 1366 1410 playNote(music, row); 1367 1411 } 1368 1412 break; 1369 1413 1370 1414 case PianoXYColumn: 1371 - if(row && row->command > tic_music_cmd_empty && hex >= 0) 1415 + if(row && row->command > tic_music_cmd_empty) 1372 1416 { 1373 - if(music->piano.edit.x & 1) 1374 - row->param2 = hex; 1375 - else row->param1 = hex; 1417 + switch (sym) 1418 + { 1419 + case '+': 1420 + case '-': 1421 + if(music->piano.edit.x & 1) 1422 + row->param2 += delta; 1423 + else row->param1 += delta; 1424 + break; 1425 + default: 1426 + if(hex >= 0) 1427 + { 1428 + if(music->piano.edit.x & 1) 1429 + row->param2 = hex; 1430 + else row->param1 = hex; 1431 + updatePianoEditCol(music); 1432 + } 1433 + } 1376 1434 1377 1435 history_add(music->history); 1378 - 1379 - updatePianoEditCol(music); 1380 1436 } 1381 1437 break; 1382 1438 } ··· 2041 2097 { 2042 2098 setCursor(music->studio, tic_cursor_hand); 2043 2099 2044 - if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2100 + bool left = checkMouseClick(music->studio, &rect, tic_mouse_left); 2101 + if(left || checkMouseClick(music->studio, &rect, tic_mouse_right)) 2045 2102 { 2046 2103 s32 col = (tic_api_mouse(tic).x - rect.x) * TIC_SOUND_CHANNELS / rect.w; 2047 2104 s32 row = (tic_api_mouse(tic).y - rect.y) * MUSIC_FRAMES / rect.h; ··· 2049 2106 // move edit cursor if pattern already selected only 2050 2107 if(col == music->piano.col && row == music->frame) 2051 2108 { 2052 - music->piano.edit.x = (tic_api_mouse(tic).x - rect.x) * TIC_SOUND_CHANNELS * 2 / rect.w; 2053 - music->piano.edit.y = row; 2109 + tic_point pos = {(tic_api_mouse(tic).x - rect.x) * TIC_SOUND_CHANNELS * 2 / rect.w, row}; 2110 + if(MEMCMP(music->piano.edit, pos)) 2111 + { 2112 + s32 step = getStep(music); 2113 + setChannelPattern(music, left ? +step : -step, pos.x / 2); 2114 + } 2115 + else music->piano.edit = pos; 2054 2116 } 2055 2117 2056 2118 music->piano.col = col; ··· 2450 2512 2451 2513 showTooltip(music->studio, "set sfx"); 2452 2514 2453 - if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2515 + bool left = checkMouseClick(music->studio, &rect, tic_mouse_left); 2516 + if(left || checkMouseClick(music->studio, &rect, tic_mouse_right)) 2454 2517 { 2455 - music->piano.edit.x = PianoSfxColumn * 2 + (tic_api_mouse(tic).x - rect.x) / TIC_FONT_WIDTH; 2456 - music->piano.edit.y = (tic_api_mouse(tic).y - rect.y) / TIC_FONT_HEIGHT; 2518 + tic_point pos = {PianoSfxColumn * 2 + (tic_api_mouse(tic).x - rect.x) / TIC_FONT_WIDTH, (tic_api_mouse(tic).y - rect.y) / TIC_FONT_HEIGHT}; 2519 + 2520 + if(MEMCMP(pos, music->piano.edit)) 2521 + { 2522 + tic_track_row* row = getPianoRow(music); 2523 + 2524 + if(row && row->note >= NoteStart) 2525 + { 2526 + s32 step = getStep(music); 2527 + s32 sfx = tic_tool_get_track_row_sfx(row) + (left ? +step : -step); 2528 + tic_tool_set_track_row_sfx(row, tic_modulo(sfx, SFX_COUNT)); 2529 + music->last.sfx = tic_tool_get_track_row_sfx(row); 2530 + history_add(music->history); 2531 + playNote(music, row); 2532 + } 2533 + } 2534 + else music->piano.edit = pos; 2457 2535 } 2458 2536 } 2459 2537 } ··· 2609 2687 } 2610 2688 } 2611 2689 2612 - if(checkMouseClick(music->studio, &rect, tic_mouse_left)) 2690 + bool left = checkMouseClick(music->studio, &rect, tic_mouse_left); 2691 + if(left || checkMouseClick(music->studio, &rect, tic_mouse_right)) 2613 2692 { 2614 - music->piano.edit.x = PianoXYColumn * 2 + (tic_api_mouse(tic).x - rect.x) / TIC_FONT_WIDTH; 2615 - music->piano.edit.y = (tic_api_mouse(tic).y - rect.y) / TIC_FONT_HEIGHT; 2693 + tic_point pos = {PianoXYColumn * 2 + (tic_api_mouse(tic).x - rect.x) / TIC_FONT_WIDTH, (tic_api_mouse(tic).y - rect.y) / TIC_FONT_HEIGHT}; 2694 + 2695 + if(MEMCMP(music->piano.edit, pos)) 2696 + { 2697 + tic_track_row* row = getPianoRow(music); 2698 + if(row && row->command > tic_music_cmd_empty) 2699 + { 2700 + s32 step = getStep(music); 2701 + s32 delta = left ? +step : -step; 2702 + if(music->piano.edit.x & 1) 2703 + row->param2 += delta; 2704 + else row->param1 += delta; 2705 + 2706 + history_add(music->history); 2707 + } 2708 + } 2709 + else music->piano.edit = pos; 2616 2710 } 2617 2711 } 2618 2712 }
+1 -1
src/tools.c
··· 174 174 175 175 void tic_tool_set_track_row_sfx(tic_track_row* row, s32 sfx) 176 176 { 177 - if(sfx >= SFX_COUNT) sfx = SFX_COUNT-1; 177 + if(sfx >= SFX_COUNT) sfx = SFX_COUNT-1; 178 178 179 179 row->sfxhi = (sfx & 0b00100000) >> MUSIC_SFXID_LOW_BITS; 180 180 row->sfxlow = sfx & 0b00011111;