ref: 4cb9cdc4475ea90ba9eb591cf00628ec60230f74
parent: c8e0c5efe33319eb553525fbbde851cd0c625111
author: Olav Sørensen <[email protected]>
date: Fri Apr 3 13:28:43 EDT 2020
Pushed v1.17 code - Fixed some bugs with sample data marking/hand-drawing and sample loop pin dragging, which appeared in v1.16.
--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -12,7 +12,7 @@
#endif
#include "ft2_replayer.h"
-#define PROG_VER_STR "1.16"
+#define PROG_VER_STR "1.17"
// do NOT change these! It will only mess things up...
--- a/src/ft2_main.c
+++ b/src/ft2_main.c
@@ -420,7 +420,7 @@
dFrac = modf(editor.dPerfFreq / VBLANK_HZ, &dInt);
// integer part
- video.vblankTimeLen = (uint32_t)dInt;
+ video.vblankTimeLen = (int32_t)dInt;
// fractional part scaled to 0..2^32-1
dFrac *= UINT32_MAX;
--- a/src/ft2_mouse.c
+++ b/src/ft2_mouse.c
@@ -718,6 +718,18 @@
#endif
}
+static void sendMouseButtonUpEvent(uint8_t button)
+{
+ SDL_Event event;
+
+ memset(&event, 0, sizeof (event));
+
+ event.type = SDL_MOUSEBUTTONUP;
+ event.button.button = button;
+
+ SDL_PushEvent(&event);
+}
+
void handleLastGUIObjectDown(void)
{
if (mouse.lastUsedObjectType == OBJECT_NONE)
@@ -771,18 +783,6 @@
{
if (video.renderW > 0.0) video.dMouseXMul = (double)SCREEN_W / video.renderW;
if (video.renderH > 0.0) video.dMouseYMul = (double)SCREEN_H / video.renderH;
-}
-
-void sendMouseButtonUpEvent(uint8_t button)
-{
- SDL_Event event;
-
- memset(&event, 0, sizeof (event));
-
- event.type = SDL_MOUSEBUTTONUP;
- event.button.button = button;
-
- SDL_PushEvent(&event);
}
void readMouseXY(void)
--- a/src/ft2_mouse.h
+++ b/src/ft2_mouse.h
@@ -31,7 +31,6 @@
#define MOUSE_GLASS_ANI_FRAMES 22
#define MOUSE_CLOCK_ANI_FRAMES 5
-void sendMouseButtonUpEvent(uint8_t button);
void freeMouseCursors(void);
bool createMouseCursors(void);
void setMousePosToCenter(void);
--- a/src/ft2_replayer.c
+++ b/src/ft2_replayer.c
@@ -334,7 +334,7 @@
dVal = dMul * (256.0 * 65536.0 * 8363.0);
frequenceMulFactor = (int32_t)(dVal + 0.5);
- audio.dScopeFreqMul = rate * (1.0 / SCOPE_HZ);
+ audio.dScopeFreqMul = rate / SCOPE_HZ;
// for volume ramping (FT2 doesn't round here)
audio.quickVolSizeVal = rate / 200;
--- a/src/ft2_sample_ed.c
+++ b/src/ft2_sample_ed.c
@@ -1180,16 +1180,6 @@
if (end < 0)
end = 0;
- // kludge so that you can mark the last sample of what we see
- // XXX: This doesn't seem to work properly!
- if (end == SCREEN_W-1)
- {
- if (smpEd_ViewSize < SAMPLE_AREA_WIDTH) // zoomed in
- end += 2;
- else if (smpEd_ScrPos+smpEd_ViewSize >= s->len)
- end++;
- }
-
smpEd_Rx1 = scr2SmpPos(start);
smpEd_Rx2 = scr2SmpPos(end);
@@ -3095,12 +3085,30 @@
updateLoopsOnMouseUp = true;
}
+static int32_t mouseYToSampleY(int32_t my)
+{
+ int32_t tmp32;
+
+ if (my == 250) // center
+ {
+ return 128;
+ }
+ else
+ {
+ tmp32 = my - 174;
+ tmp32 = ((tmp32 << 8) + (SAMPLE_AREA_HEIGHT/2)) / SAMPLE_AREA_HEIGHT;
+ tmp32 = CLAMP(tmp32, 0, 255);
+ tmp32 ^= 0xFF;
+ }
+
+ return tmp32;
+}
+
static void editSampleData(bool mouseButtonHeld)
{
int8_t *ptr8;
int16_t *ptr16;
int32_t mx, my, tmp32, p, vl, tvl, r, rl, rvl, start, end;
- double dVal;
sampleTyp *s = getCurSample();
if (s == NULL || s->pek == NULL || s->len <= 0)
@@ -3109,6 +3117,9 @@
// ported directly from FT2 and slightly modified
mx = mouse.x;
+ if (mx > SCREEN_W)
+ mx = SCREEN_W;
+
my = mouse.y;
if (!mouseButtonHeld)
@@ -3121,17 +3132,7 @@
if (s->typ & 16)
lastDrawX >>= 1;
- if (my == 250) // center
- {
- lastDrawY = 128;
- }
- else
- {
- dVal = (my - 174) * (256.0 / SAMPLE_AREA_HEIGHT);
- lastDrawY = (int32_t)(dVal + 0.5);
- lastDrawY = CLAMP(lastDrawY, 0, 255);
- lastDrawY ^= 0xFF;
- }
+ lastDrawY = mouseYToSampleY(my);
lastMouseX = mx;
lastMouseY = my;
@@ -3141,10 +3142,6 @@
return; // don't continue if we didn't move the mouse
}
- // kludge so that you can edit the very end of the sample
- if (mx == SCREEN_W-1 && smpEd_ScrPos+smpEd_ViewSize >= s->len)
- mx++;
-
if (mx != lastMouseX)
{
p = scr2SmpPos(mx);
@@ -3157,23 +3154,9 @@
}
if (!keyb.leftShiftPressed && my != lastMouseY)
- {
- if (my == 250) // center
- {
- vl = 128;
- }
- else
- {
- dVal = (my - 174) * (256.0 / SAMPLE_AREA_HEIGHT);
- vl = (int32_t)(dVal + 0.5);
- vl = CLAMP(vl, 0, 255);
- vl ^= 0xFF;
- }
- }
+ vl = mouseYToSampleY(my);
else
- {
vl = lastDrawY;
- }
lastMouseX = mx;
lastMouseY = my;
@@ -3213,7 +3196,7 @@
if (p == lastDrawX)
{
- int16_t smpVal = (int16_t)((vl << 8) ^ 0x8000);
+ const int16_t smpVal = (int16_t)((vl << 8) ^ 0x8000);
for (rl = start; rl < end; rl++)
ptr16[rl] = smpVal;
}
@@ -3220,23 +3203,24 @@
else
{
int32_t y = lastDrawY - vl;
- uint32_t x = lastDrawX - p;
+ int32_t x = lastDrawX - p;
- int32_t xMul = 0xFFFFFFFF;
if (x != 0)
- xMul /= x;
-
- int32_t i = 0;
- for (rl = start; rl < end; rl++)
{
- tvl = y * i;
- tvl = ((int64_t)tvl * xMul) >> 32; // tvl /= x;
- tvl += vl;
- tvl <<= 8;
- tvl ^= 0x8000;
+ double dMul = 1.0 / x;
+ int32_t i = 0;
- ptr16[rl] = (int16_t)tvl;
- i++;
+ for (rl = start; rl < end; rl++)
+ {
+ tvl = y * i;
+ tvl = (int32_t)(tvl * dMul); // tvl /= x
+ tvl += vl;
+ tvl <<= 8;
+ tvl ^= 0x8000;
+
+ ptr16[rl] = (int16_t)tvl;
+ i++;
+ }
}
}
}
@@ -3256,7 +3240,7 @@
if (p == lastDrawX)
{
- int8_t smpVal = (int8_t)(vl ^ 0x80);
+ const int8_t smpVal = (int8_t)(vl ^ 0x80);
for (rl = start; rl < end; rl++)
ptr8[rl] = smpVal;
}
@@ -3263,22 +3247,23 @@
else
{
int32_t y = lastDrawY - vl;
- uint32_t x = lastDrawX - p;
+ int32_t x = lastDrawX - p;
- int32_t xMul = 0xFFFFFFFF;
if (x != 0)
- xMul /= x;
-
- int32_t i = 0;
- for (rl = start; rl < end; rl++)
{
- tvl = y * i;
- tvl = ((int64_t)tvl * xMul) >> 32; // tvl /= x;
- tvl += vl;
- tvl ^= 0x80;
+ double dMul = 1.0 / x;
+ int32_t i = 0;
- ptr8[rl] = (int8_t)tvl;
- i++;
+ for (rl = start; rl < end; rl++)
+ {
+ tvl = y * i;
+ tvl = (int32_t)(tvl * dMul); // tvl /= x
+ tvl += vl;
+ tvl ^= 0x80;
+
+ ptr8[rl] = (int8_t)tvl;
+ i++;
+ }
}
}
}
@@ -3291,11 +3276,14 @@
void handleSampleDataMouseDown(bool mouseButtonHeld)
{
- int32_t tmp, leftLoopPinPos, rightLoopPinPos;
+ int32_t mx, my, leftLoopPinPos, rightLoopPinPos;
if (editor.curInstr == 0)
return;
+ mx = CLAMP(mouse.x, 0, SCREEN_W+8); // allow some pixels outside of the screen
+ my = CLAMP(mouse.y, 0, SCREEN_H-1);
+
if (!mouseButtonHeld)
{
editor.ui.rightLoopPinMoving = false;
@@ -3303,8 +3291,8 @@
editor.ui.sampleDataOrLoopDrag = -1;
mouseXOffs = 0;
- lastMouseX = mouse.x;
- lastMouseY = mouse.y;
+ lastMouseX = mx;
+ lastMouseY = my;
mouse.lastUsedObjectType = OBJECT_SMPDATA;
@@ -3311,33 +3299,33 @@
if (mouse.leftButtonPressed)
{
// move loop pins
- if (mouse.y < 183)
+ if (my < 183)
{
leftLoopPinPos = getSpritePosX(SPRITE_LEFT_LOOP_PIN);
- if (mouse.x >= leftLoopPinPos && mouse.x <= leftLoopPinPos+16)
+ if (mx >= leftLoopPinPos && mx <= leftLoopPinPos+16)
{
- mouseXOffs = (leftLoopPinPos + 8) - mouse.x;
+ mouseXOffs = (leftLoopPinPos + 8) - mx;
editor.ui.sampleDataOrLoopDrag = true;
setLeftLoopPinState(true);
- lastMouseX = mouse.x;
+ lastMouseX = mx;
editor.ui.leftLoopPinMoving = true;
return;
}
}
- else if (mouse.y > 318)
+ else if (my > 318)
{
rightLoopPinPos = getSpritePosX(SPRITE_RIGHT_LOOP_PIN);
- if (mouse.x >= rightLoopPinPos && mouse.x <= rightLoopPinPos+16)
+ if (mx >= rightLoopPinPos && mx <= rightLoopPinPos+16)
{
- mouseXOffs = (rightLoopPinPos + 8) - mouse.x;
+ mouseXOffs = (rightLoopPinPos + 8) - mx;
editor.ui.sampleDataOrLoopDrag = true;
setRightLoopPinState(true);
- lastMouseX = mouse.x;
+ lastMouseX = mx;
editor.ui.rightLoopPinMoving = true;
return;
@@ -3345,9 +3333,10 @@
}
// mark data
- editor.ui.sampleDataOrLoopDrag = mouse.x;
- lastMouseX = editor.ui.sampleDataOrLoopDrag;
- setSampleRange(editor.ui.sampleDataOrLoopDrag, editor.ui.sampleDataOrLoopDrag);
+ lastMouseX = mx;
+ editor.ui.sampleDataOrLoopDrag = mx;
+
+ setSampleRange(mx, mx);
}
else if (mouse.rightButtonPressed)
{
@@ -3365,33 +3354,31 @@
return;
}
- if (mouse.x != lastMouseX)
+ if (mx != lastMouseX)
{
if (mouse.leftButtonPressed)
{
if (editor.ui.leftLoopPinMoving)
{
- lastMouseX = mouse.x;
- setLeftLoopPinPos(mouseXOffs + lastMouseX);
+ lastMouseX = mx;
+ setLeftLoopPinPos(mouseXOffs + mx);
}
else if (editor.ui.rightLoopPinMoving)
{
- lastMouseX = mouse.x;
- setRightLoopPinPos(mouseXOffs + lastMouseX);
+ lastMouseX = mx;
+ setRightLoopPinPos(mouseXOffs + mx);
}
else if (editor.ui.sampleDataOrLoopDrag >= 0)
{
// mark data
+ lastMouseX = mx;
- lastMouseX = mouse.x;
- tmp = lastMouseX;
-
- if (lastMouseX > editor.ui.sampleDataOrLoopDrag)
- setSampleRange(editor.ui.sampleDataOrLoopDrag, tmp);
+ if (lastMouseX > editor.ui.sampleDataOrLoopDrag)
+ setSampleRange(editor.ui.sampleDataOrLoopDrag, mx);
else if (lastMouseX == editor.ui.sampleDataOrLoopDrag)
setSampleRange(editor.ui.sampleDataOrLoopDrag, editor.ui.sampleDataOrLoopDrag);
- else if (lastMouseX < editor.ui.sampleDataOrLoopDrag)
- setSampleRange(tmp, editor.ui.sampleDataOrLoopDrag);
+ else if (lastMouseX < editor.ui.sampleDataOrLoopDrag)
+ setSampleRange(mx, editor.ui.sampleDataOrLoopDrag);
}
}
}
--- a/src/ft2_video.c
+++ b/src/ft2_video.c
@@ -260,8 +260,8 @@
if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale);
if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale);
#endif
- video.renderX = (video.displayW - video.renderW) / 2;
- video.renderY = (video.displayH - video.renderH) / 2;
+ video.renderX = (video.displayW - video.renderW) >> 1;
+ video.renderY = (video.displayH - video.renderH) >> 1;
}
}
else
@@ -273,8 +273,8 @@
}
// for mouse cursor creation
- video.xScale = (uint32_t)round(video.renderW / (double)SCREEN_W);
- video.yScale = (uint32_t)round(video.renderH / (double)SCREEN_H);
+ video.xScale = (uint32_t)round(video.renderW * (1.0 / SCREEN_W));
+ video.yScale = (uint32_t)round(video.renderH * (1.0 / SCREEN_H));
createMouseCursors();
}