History

Pushed v1.17 code

- Fixed some bugs with sample data marking/hand-drawing and sample loop pin dragging, which appeared in v1.16.

Olav Sørensen committed 6 years ago

Commit 4cb9cdc1 parent c8e0c5e7 files · +101 −115Browse files

Unified · Split

7 files
  1. src/ft2_header.h +1 −1
  2. src/ft2_main.c +1 −1
  3. src/ft2_mouse.c +12 −12
  4. src/ft2_mouse.h +0 −1
  5. src/ft2_replayer.c +1 −1
  6. src/ft2_sample_ed.c +82 −95
  7. src/ft2_video.c +4 −4
src/ft2_header.h+1−1
@@ -12,7 +12,7 @@ · 11 unmodified lines
1212 #endif
1313 #include "ft2_replayer.h"
1414
15−#define PROG_VER_STR "1.16"
15+#define PROG_VER_STR "1.17"
1616
1717 // do NOT change these! It will only mess things up...
1818
src/ft2_main.c+1−1
@@ -420,7 +420,7 @@ static void setupPerfFreq(void) · 419 unmodified lines
420420 dFrac = modf(editor.dPerfFreq / VBLANK_HZ, &dInt);
421421
422422 // integer part
423− video.vblankTimeLen = (uint32_t)dInt;
423+ video.vblankTimeLen = (int32_t)dInt;
424424
425425 // fractional part scaled to 0..2^32-1
426426 dFrac *= UINT32_MAX;
src/ft2_mouse.c+12−12
@@ -718,6 +718,18 @@ void mouseButtonDownHandler(uint8_t mouseButton) · 717 unmodified lines
718718 #endif
719719 }
720720
721+static void sendMouseButtonUpEvent(uint8_t button)
722+{
723+ SDL_Event event;
724+
725+ memset(&event, 0, sizeof (event));
726+
727+ event.type = SDL_MOUSEBUTTONUP;
728+ event.button.button = button;
729+
730+ SDL_PushEvent(&event);
731+}
732+
721733 void handleLastGUIObjectDown(void)
722734 {
723735 if (mouse.lastUsedObjectType == OBJECT_NONE)
@@ -773,18 +785,6 @@ void updateMouseScaling(void) · 49 unmodified lines
773785 if (video.renderH > 0.0) video.dMouseYMul = (double)SCREEN_H / video.renderH;
774786 }
775787
776−void sendMouseButtonUpEvent(uint8_t button)
777−{
778− SDL_Event event;
779−
780− memset(&event, 0, sizeof (event));
781−
782− event.type = SDL_MOUSEBUTTONUP;
783− event.button.button = button;
784−
785− SDL_PushEvent(&event);
786−}
787−
788788 void readMouseXY(void)
789789 {
790790 int32_t mx, my, windowX, windowY;
src/ft2_mouse.h+0−1
@@ -31,7 +31,6 @@ struct mouse_t · 30 unmodified lines
3131 #define MOUSE_GLASS_ANI_FRAMES 22
3232 #define MOUSE_CLOCK_ANI_FRAMES 5
3333
34−void sendMouseButtonUpEvent(uint8_t button);
3534 void freeMouseCursors(void);
3635 bool createMouseCursors(void);
3736 void setMousePosToCenter(void);
src/ft2_replayer.c+1−1
@@ -334,7 +334,7 @@ void calcReplayRate(int32_t rate) // 100% FT2-accurate routine, do not touch! · 333 unmodified lines
334334 dVal = dMul * (256.0 * 65536.0 * 8363.0);
335335 frequenceMulFactor = (int32_t)(dVal + 0.5);
336336
337− audio.dScopeFreqMul = rate * (1.0 / SCOPE_HZ);
337+ audio.dScopeFreqMul = rate / SCOPE_HZ;
338338
339339 // for volume ramping (FT2 doesn't round here)
340340 audio.quickVolSizeVal = rate / 200;
src/ft2_sample_ed.c+82−95
@@ -1180,16 +1180,6 @@ static void setSampleRange(int32_t start, int32_t end) · 1179 unmodified lines
11801180 if (end < 0)
11811181 end = 0;
11821182
1183− // kludge so that you can mark the last sample of what we see
1184− // XXX: This doesn't seem to work properly!
1185− if (end == SCREEN_W-1)
1186− {
1187− if (smpEd_ViewSize < SAMPLE_AREA_WIDTH) // zoomed in
1188− end += 2;
1189− else if (smpEd_ScrPos+smpEd_ViewSize >= s->len)
1190− end++;
1191− }
1192−
11931183 smpEd_Rx1 = scr2SmpPos(start);
11941184 smpEd_Rx2 = scr2SmpPos(end);
11951185
@@ -3095,12 +3085,30 @@ static void setRightLoopPinPos(int32_t x) · 1899 unmodified lines
30953085 updateLoopsOnMouseUp = true;
30963086 }
30973087
3088+static int32_t mouseYToSampleY(int32_t my)
3089+{
3090+ int32_t tmp32;
3091+
3092+ if (my == 250) // center
3093+ {
3094+ return 128;
3095+ }
3096+ else
3097+ {
3098+ tmp32 = my - 174;
3099+ tmp32 = ((tmp32 << 8) + (SAMPLE_AREA_HEIGHT/2)) / SAMPLE_AREA_HEIGHT;
3100+ tmp32 = CLAMP(tmp32, 0, 255);
3101+ tmp32 ^= 0xFF;
3102+ }
3103+
3104+ return tmp32;
3105+}
3106+
30983107 static void editSampleData(bool mouseButtonHeld)
30993108 {
31003109 int8_t *ptr8;
31013110 int16_t *ptr16;
31023111 int32_t mx, my, tmp32, p, vl, tvl, r, rl, rvl, start, end;
3103− double dVal;
31043112 sampleTyp *s = getCurSample();
31053113
31063114 if (s == NULL || s->pek == NULL || s->len <= 0)
@@ -3109,6 +3117,9 @@ static void editSampleData(bool mouseButtonHeld) · 2 unmodified lines
31093117 // ported directly from FT2 and slightly modified
31103118
31113119 mx = mouse.x;
3120+ if (mx > SCREEN_W)
3121+ mx = SCREEN_W;
3122+
31123123 my = mouse.y;
31133124
31143125 if (!mouseButtonHeld)
@@ -3121,17 +3132,7 @@ static void editSampleData(bool mouseButtonHeld) · 6 unmodified lines
31213132 if (s->typ & 16)
31223133 lastDrawX >>= 1;
31233134
3124− if (my == 250) // center
3125− {
3126− lastDrawY = 128;
3127− }
3128− else
3129− {
3130− dVal = (my - 174) * (256.0 / SAMPLE_AREA_HEIGHT);
3131− lastDrawY = (int32_t)(dVal + 0.5);
3132− lastDrawY = CLAMP(lastDrawY, 0, 255);
3133− lastDrawY ^= 0xFF;
3134− }
3135+ lastDrawY = mouseYToSampleY(my);
31353136
31363137 lastMouseX = mx;
31373138 lastMouseY = my;
@@ -3141,10 +3142,6 @@ static void editSampleData(bool mouseButtonHeld) · 3 unmodified lines
31413142 return; // don't continue if we didn't move the mouse
31423143 }
31433144
3144− // kludge so that you can edit the very end of the sample
3145− if (mx == SCREEN_W-1 && smpEd_ScrPos+smpEd_ViewSize >= s->len)
3146− mx++;
3147−
31483145 if (mx != lastMouseX)
31493146 {
31503147 p = scr2SmpPos(mx);
@@ -3157,23 +3154,9 @@ static void editSampleData(bool mouseButtonHeld) · 6 unmodified lines
31573154 }
31583155
31593156 if (!keyb.leftShiftPressed && my != lastMouseY)
3160− {
3161− if (my == 250) // center
3162− {
3163− vl = 128;
3164− }
3165− else
3166− {
3167− dVal = (my - 174) * (256.0 / SAMPLE_AREA_HEIGHT);
3168− vl = (int32_t)(dVal + 0.5);
3169− vl = CLAMP(vl, 0, 255);
3170− vl ^= 0xFF;
3171− }
3172− }
3157+ vl = mouseYToSampleY(my);
31733158 else
3174− {
31753159 vl = lastDrawY;
3176− }
31773160
31783161 lastMouseX = mx;
31793162 lastMouseY = my;
@@ -3213,30 +3196,31 @@ static void editSampleData(bool mouseButtonHeld) · 33 unmodified lines
32133196
32143197 if (p == lastDrawX)
32153198 {
3216− int16_t smpVal = (int16_t)((vl << 8) ^ 0x8000);
3199+ const int16_t smpVal = (int16_t)((vl << 8) ^ 0x8000);
32173200 for (rl = start; rl < end; rl++)
32183201 ptr16[rl] = smpVal;
32193202 }
32203203 else
32213204 {
32223205 int32_t y = lastDrawY - vl;
3223− uint32_t x = lastDrawX - p;
3206+ int32_t x = lastDrawX - p;
32243207
3225− int32_t xMul = 0xFFFFFFFF;
32263208 if (x != 0)
3227− xMul /= x;
3228−
3229− int32_t i = 0;
3230− for (rl = start; rl < end; rl++)
32313209 {
3232− tvl = y * i;
3233− tvl = ((int64_t)tvl * xMul) >> 32; // tvl /= x;
3234− tvl += vl;
3235− tvl <<= 8;
3236− tvl ^= 0x8000;
3237−
3238− ptr16[rl] = (int16_t)tvl;
3239− i++;
3210+ double dMul = 1.0 / x;
3211+ int32_t i = 0;
3212+
3213+ for (rl = start; rl < end; rl++)
3214+ {
3215+ tvl = y * i;
3216+ tvl = (int32_t)(tvl * dMul); // tvl /= x
3217+ tvl += vl;
3218+ tvl <<= 8;
3219+ tvl ^= 0x8000;
3220+
3221+ ptr16[rl] = (int16_t)tvl;
3222+ i++;
3223+ }
32403224 }
32413225 }
32423226 }
@@ -3256,29 +3240,30 @@ static void editSampleData(bool mouseButtonHeld) · 13 unmodified lines
32563240
32573241 if (p == lastDrawX)
32583242 {
3259− int8_t smpVal = (int8_t)(vl ^ 0x80);
3243+ const int8_t smpVal = (int8_t)(vl ^ 0x80);
32603244 for (rl = start; rl < end; rl++)
32613245 ptr8[rl] = smpVal;
32623246 }
32633247 else
32643248 {
32653249 int32_t y = lastDrawY - vl;
3266− uint32_t x = lastDrawX - p;
3250+ int32_t x = lastDrawX - p;
32673251
3268− int32_t xMul = 0xFFFFFFFF;
32693252 if (x != 0)
3270− xMul /= x;
3271−
3272− int32_t i = 0;
3273− for (rl = start; rl < end; rl++)
32743253 {
3275− tvl = y * i;
3276− tvl = ((int64_t)tvl * xMul) >> 32; // tvl /= x;
3277− tvl += vl;
3278− tvl ^= 0x80;
3254+ double dMul = 1.0 / x;
3255+ int32_t i = 0;
3256+
3257+ for (rl = start; rl < end; rl++)
3258+ {
3259+ tvl = y * i;
3260+ tvl = (int32_t)(tvl * dMul); // tvl /= x
3261+ tvl += vl;
3262+ tvl ^= 0x80;
32793263
3280− ptr8[rl] = (int8_t)tvl;
3281− i++;
3264+ ptr8[rl] = (int8_t)tvl;
3265+ i++;
3266+ }
32823267 }
32833268 }
32843269 }
@@ -3291,11 +3276,14 @@ static void editSampleData(bool mouseButtonHeld) · 6 unmodified lines
32913276
32923277 void handleSampleDataMouseDown(bool mouseButtonHeld)
32933278 {
3294− int32_t tmp, leftLoopPinPos, rightLoopPinPos;
3279+ int32_t mx, my, leftLoopPinPos, rightLoopPinPos;
32953280
32963281 if (editor.curInstr == 0)
32973282 return;
32983283
3284+ mx = CLAMP(mouse.x, 0, SCREEN_W+8); // allow some pixels outside of the screen
3285+ my = CLAMP(mouse.y, 0, SCREEN_H-1);
3286+
32993287 if (!mouseButtonHeld)
33003288 {
33013289 editor.ui.rightLoopPinMoving = false;
@@ -3303,41 +3291,41 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) · 1 unmodified line
33033291 editor.ui.sampleDataOrLoopDrag = -1;
33043292
33053293 mouseXOffs = 0;
3306− lastMouseX = mouse.x;
3307− lastMouseY = mouse.y;
3294+ lastMouseX = mx;
3295+ lastMouseY = my;
33083296
33093297 mouse.lastUsedObjectType = OBJECT_SMPDATA;
33103298
33113299 if (mouse.leftButtonPressed)
33123300 {
33133301 // move loop pins
3314− if (mouse.y < 183)
3302+ if (my < 183)
33153303 {
33163304 leftLoopPinPos = getSpritePosX(SPRITE_LEFT_LOOP_PIN);
3317− if (mouse.x >= leftLoopPinPos && mouse.x <= leftLoopPinPos+16)
3305+ if (mx >= leftLoopPinPos && mx <= leftLoopPinPos+16)
33183306 {
3319− mouseXOffs = (leftLoopPinPos + 8) - mouse.x;
3307+ mouseXOffs = (leftLoopPinPos + 8) - mx;
33203308
33213309 editor.ui.sampleDataOrLoopDrag = true;
33223310
33233311 setLeftLoopPinState(true);
3324− lastMouseX = mouse.x;
3312+ lastMouseX = mx;
33253313
33263314 editor.ui.leftLoopPinMoving = true;
33273315 return;
33283316 }
33293317 }
3330− else if (mouse.y > 318)
3318+ else if (my > 318)
33313319 {
33323320 rightLoopPinPos = getSpritePosX(SPRITE_RIGHT_LOOP_PIN);
3333− if (mouse.x >= rightLoopPinPos && mouse.x <= rightLoopPinPos+16)
3321+ if (mx >= rightLoopPinPos && mx <= rightLoopPinPos+16)
33343322 {
3335− mouseXOffs = (rightLoopPinPos + 8) - mouse.x;
3323+ mouseXOffs = (rightLoopPinPos + 8) - mx;
33363324
33373325 editor.ui.sampleDataOrLoopDrag = true;
33383326
33393327 setRightLoopPinState(true);
3340− lastMouseX = mouse.x;
3328+ lastMouseX = mx;
33413329
33423330 editor.ui.rightLoopPinMoving = true;
33433331 return;
@@ -3345,9 +3333,10 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) · 1 unmodified line
33453333 }
33463334
33473335 // mark data
3348− editor.ui.sampleDataOrLoopDrag = mouse.x;
3349− lastMouseX = editor.ui.sampleDataOrLoopDrag;
3350− setSampleRange(editor.ui.sampleDataOrLoopDrag, editor.ui.sampleDataOrLoopDrag);
3336+ lastMouseX = mx;
3337+ editor.ui.sampleDataOrLoopDrag = mx;
3338+
3339+ setSampleRange(mx, mx);
33513340 }
33523341 else if (mouse.rightButtonPressed)
33533342 {
@@ -3365,33 +3354,31 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) · 11 unmodified lines
33653354 return;
33663355 }
33673356
3368− if (mouse.x != lastMouseX)
3357+ if (mx != lastMouseX)
33693358 {
33703359 if (mouse.leftButtonPressed)
33713360 {
33723361 if (editor.ui.leftLoopPinMoving)
33733362 {
3374− lastMouseX = mouse.x;
3375− setLeftLoopPinPos(mouseXOffs + lastMouseX);
3363+ lastMouseX = mx;
3364+ setLeftLoopPinPos(mouseXOffs + mx);
33763365 }
33773366 else if (editor.ui.rightLoopPinMoving)
33783367 {
3379− lastMouseX = mouse.x;
3380− setRightLoopPinPos(mouseXOffs + lastMouseX);
3368+ lastMouseX = mx;
3369+ setRightLoopPinPos(mouseXOffs + mx);
33813370 }
33823371 else if (editor.ui.sampleDataOrLoopDrag >= 0)
33833372 {
33843373 // mark data
3374+ lastMouseX = mx;
33853375
3386− lastMouseX = mouse.x;
3387− tmp = lastMouseX;
3388−
3389− if (lastMouseX > editor.ui.sampleDataOrLoopDrag)
3390− setSampleRange(editor.ui.sampleDataOrLoopDrag, tmp);
3376+ if (lastMouseX > editor.ui.sampleDataOrLoopDrag)
3377+ setSampleRange(editor.ui.sampleDataOrLoopDrag, mx);
33913378 else if (lastMouseX == editor.ui.sampleDataOrLoopDrag)
33923379 setSampleRange(editor.ui.sampleDataOrLoopDrag, editor.ui.sampleDataOrLoopDrag);
3393− else if (lastMouseX < editor.ui.sampleDataOrLoopDrag)
3394− setSampleRange(tmp, editor.ui.sampleDataOrLoopDrag);
3380+ else if (lastMouseX < editor.ui.sampleDataOrLoopDrag)
3381+ setSampleRange(mx, editor.ui.sampleDataOrLoopDrag);
33953382 }
33963383 }
33973384 }
src/ft2_video.c+4−4
@@ -260,8 +260,8 @@ static void updateRenderSizeVars(void) · 259 unmodified lines
260260 if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale);
261261 if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale);
262262 #endif
263− video.renderX = (video.displayW - video.renderW) / 2;
264− video.renderY = (video.displayH - video.renderH) / 2;
263+ video.renderX = (video.displayW - video.renderW) >> 1;
264+ video.renderY = (video.displayH - video.renderH) >> 1;
265265 }
266266 }
267267 else
@@ -273,8 +273,8 @@ static void updateRenderSizeVars(void) · 5 unmodified lines
273273 }
274274
275275 // for mouse cursor creation
276− video.xScale = (uint32_t)round(video.renderW / (double)SCREEN_W);
277− video.yScale = (uint32_t)round(video.renderH / (double)SCREEN_H);
276+ video.xScale = (uint32_t)round(video.renderW * (1.0 / SCREEN_W));
277+ video.yScale = (uint32_t)round(video.renderH * (1.0 / SCREEN_H));
278278 createMouseCursors();
279279 }
280280

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t