| @@ -1180,16 +1180,6 @@ static void setSampleRange(int32_t start, int32_t end) · 1179 unmodified lines |
| 1180 | 1180 | if (end < 0) |
| 1181 | 1181 | end = 0; |
| 1182 | 1182 | |
| 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 | | − |
| 1193 | 1183 | smpEd_Rx1 = scr2SmpPos(start); |
| 1194 | 1184 | smpEd_Rx2 = scr2SmpPos(end); |
| 1195 | 1185 | |
| @@ -3095,12 +3085,30 @@ static void setRightLoopPinPos(int32_t x) · 1899 unmodified lines |
| 3095 | 3085 | updateLoopsOnMouseUp = true; |
| 3096 | 3086 | } |
| 3097 | 3087 | |
| 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 | + |
| 3098 | 3107 | static void editSampleData(bool mouseButtonHeld) |
| 3099 | 3108 | { |
| 3100 | 3109 | int8_t *ptr8; |
| 3101 | 3110 | int16_t *ptr16; |
| 3102 | 3111 | int32_t mx, my, tmp32, p, vl, tvl, r, rl, rvl, start, end; |
| 3103 | | − double dVal; |
| 3104 | 3112 | sampleTyp *s = getCurSample(); |
| 3105 | 3113 | |
| 3106 | 3114 | if (s == NULL || s->pek == NULL || s->len <= 0) |
| @@ -3109,6 +3117,9 @@ static void editSampleData(bool mouseButtonHeld) · 2 unmodified lines |
| 3109 | 3117 | // ported directly from FT2 and slightly modified |
| 3110 | 3118 | |
| 3111 | 3119 | mx = mouse.x; |
| 3120 | + if (mx > SCREEN_W) |
| 3121 | + mx = SCREEN_W; |
| 3122 | + |
| 3112 | 3123 | my = mouse.y; |
| 3113 | 3124 | |
| 3114 | 3125 | if (!mouseButtonHeld) |
| @@ -3121,17 +3132,7 @@ static void editSampleData(bool mouseButtonHeld) · 6 unmodified lines |
| 3121 | 3132 | if (s->typ & 16) |
| 3122 | 3133 | lastDrawX >>= 1; |
| 3123 | 3134 | |
| 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); |
| 3135 | 3136 | |
| 3136 | 3137 | lastMouseX = mx; |
| 3137 | 3138 | lastMouseY = my; |
| @@ -3141,10 +3142,6 @@ static void editSampleData(bool mouseButtonHeld) · 3 unmodified lines |
| 3141 | 3142 | return; // don't continue if we didn't move the mouse |
| 3142 | 3143 | } |
| 3143 | 3144 | |
| 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 | | − |
| 3148 | 3145 | if (mx != lastMouseX) |
| 3149 | 3146 | { |
| 3150 | 3147 | p = scr2SmpPos(mx); |
| @@ -3157,23 +3154,9 @@ static void editSampleData(bool mouseButtonHeld) · 6 unmodified lines |
| 3157 | 3154 | } |
| 3158 | 3155 | |
| 3159 | 3156 | 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); |
| 3173 | 3158 | else |
| 3174 | | − { |
| 3175 | 3159 | vl = lastDrawY; |
| 3176 | | − } |
| 3177 | 3160 | |
| 3178 | 3161 | lastMouseX = mx; |
| 3179 | 3162 | lastMouseY = my; |
| @@ -3213,30 +3196,31 @@ static void editSampleData(bool mouseButtonHeld) · 33 unmodified lines |
| 3213 | 3196 | |
| 3214 | 3197 | if (p == lastDrawX) |
| 3215 | 3198 | { |
| 3216 | | − int16_t smpVal = (int16_t)((vl << 8) ^ 0x8000); |
| 3199 | + const int16_t smpVal = (int16_t)((vl << 8) ^ 0x8000); |
| 3217 | 3200 | for (rl = start; rl < end; rl++) |
| 3218 | 3201 | ptr16[rl] = smpVal; |
| 3219 | 3202 | } |
| 3220 | 3203 | else |
| 3221 | 3204 | { |
| 3222 | 3205 | int32_t y = lastDrawY - vl; |
| 3223 | | − uint32_t x = lastDrawX - p; |
| 3206 | + int32_t x = lastDrawX - p; |
| 3224 | 3207 | |
| 3225 | | − int32_t xMul = 0xFFFFFFFF; |
| 3226 | 3208 | if (x != 0) |
| 3227 | | − xMul /= x; |
| 3228 | | − |
| 3229 | | − int32_t i = 0; |
| 3230 | | − for (rl = start; rl < end; rl++) |
| 3231 | 3209 | { |
| 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 | + } |
| 3240 | 3224 | } |
| 3241 | 3225 | } |
| 3242 | 3226 | } |
| @@ -3256,29 +3240,30 @@ static void editSampleData(bool mouseButtonHeld) · 13 unmodified lines |
| 3256 | 3240 | |
| 3257 | 3241 | if (p == lastDrawX) |
| 3258 | 3242 | { |
| 3259 | | − int8_t smpVal = (int8_t)(vl ^ 0x80); |
| 3243 | + const int8_t smpVal = (int8_t)(vl ^ 0x80); |
| 3260 | 3244 | for (rl = start; rl < end; rl++) |
| 3261 | 3245 | ptr8[rl] = smpVal; |
| 3262 | 3246 | } |
| 3263 | 3247 | else |
| 3264 | 3248 | { |
| 3265 | 3249 | int32_t y = lastDrawY - vl; |
| 3266 | | − uint32_t x = lastDrawX - p; |
| 3250 | + int32_t x = lastDrawX - p; |
| 3267 | 3251 | |
| 3268 | | − int32_t xMul = 0xFFFFFFFF; |
| 3269 | 3252 | if (x != 0) |
| 3270 | | − xMul /= x; |
| 3271 | | − |
| 3272 | | − int32_t i = 0; |
| 3273 | | − for (rl = start; rl < end; rl++) |
| 3274 | 3253 | { |
| 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; |
| 3279 | 3263 | |
| 3280 | | − ptr8[rl] = (int8_t)tvl; |
| 3281 | | − i++; |
| 3264 | + ptr8[rl] = (int8_t)tvl; |
| 3265 | + i++; |
| 3266 | + } |
| 3282 | 3267 | } |
| 3283 | 3268 | } |
| 3284 | 3269 | } |
| @@ -3291,11 +3276,14 @@ static void editSampleData(bool mouseButtonHeld) · 6 unmodified lines |
| 3291 | 3276 | |
| 3292 | 3277 | void handleSampleDataMouseDown(bool mouseButtonHeld) |
| 3293 | 3278 | { |
| 3294 | | − int32_t tmp, leftLoopPinPos, rightLoopPinPos; |
| 3279 | + int32_t mx, my, leftLoopPinPos, rightLoopPinPos; |
| 3295 | 3280 | |
| 3296 | 3281 | if (editor.curInstr == 0) |
| 3297 | 3282 | return; |
| 3298 | 3283 | |
| 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 | + |
| 3299 | 3287 | if (!mouseButtonHeld) |
| 3300 | 3288 | { |
| 3301 | 3289 | editor.ui.rightLoopPinMoving = false; |
| @@ -3303,41 +3291,41 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) · 1 unmodified line |
| 3303 | 3291 | editor.ui.sampleDataOrLoopDrag = -1; |
| 3304 | 3292 | |
| 3305 | 3293 | mouseXOffs = 0; |
| 3306 | | − lastMouseX = mouse.x; |
| 3307 | | − lastMouseY = mouse.y; |
| 3294 | + lastMouseX = mx; |
| 3295 | + lastMouseY = my; |
| 3308 | 3296 | |
| 3309 | 3297 | mouse.lastUsedObjectType = OBJECT_SMPDATA; |
| 3310 | 3298 | |
| 3311 | 3299 | if (mouse.leftButtonPressed) |
| 3312 | 3300 | { |
| 3313 | 3301 | // move loop pins |
| 3314 | | − if (mouse.y < 183) |
| 3302 | + if (my < 183) |
| 3315 | 3303 | { |
| 3316 | 3304 | leftLoopPinPos = getSpritePosX(SPRITE_LEFT_LOOP_PIN); |
| 3317 | | − if (mouse.x >= leftLoopPinPos && mouse.x <= leftLoopPinPos+16) |
| 3305 | + if (mx >= leftLoopPinPos && mx <= leftLoopPinPos+16) |
| 3318 | 3306 | { |
| 3319 | | − mouseXOffs = (leftLoopPinPos + 8) - mouse.x; |
| 3307 | + mouseXOffs = (leftLoopPinPos + 8) - mx; |
| 3320 | 3308 | |
| 3321 | 3309 | editor.ui.sampleDataOrLoopDrag = true; |
| 3322 | 3310 | |
| 3323 | 3311 | setLeftLoopPinState(true); |
| 3324 | | − lastMouseX = mouse.x; |
| 3312 | + lastMouseX = mx; |
| 3325 | 3313 | |
| 3326 | 3314 | editor.ui.leftLoopPinMoving = true; |
| 3327 | 3315 | return; |
| 3328 | 3316 | } |
| 3329 | 3317 | } |
| 3330 | | − else if (mouse.y > 318) |
| 3318 | + else if (my > 318) |
| 3331 | 3319 | { |
| 3332 | 3320 | rightLoopPinPos = getSpritePosX(SPRITE_RIGHT_LOOP_PIN); |
| 3333 | | − if (mouse.x >= rightLoopPinPos && mouse.x <= rightLoopPinPos+16) |
| 3321 | + if (mx >= rightLoopPinPos && mx <= rightLoopPinPos+16) |
| 3334 | 3322 | { |
| 3335 | | − mouseXOffs = (rightLoopPinPos + 8) - mouse.x; |
| 3323 | + mouseXOffs = (rightLoopPinPos + 8) - mx; |
| 3336 | 3324 | |
| 3337 | 3325 | editor.ui.sampleDataOrLoopDrag = true; |
| 3338 | 3326 | |
| 3339 | 3327 | setRightLoopPinState(true); |
| 3340 | | − lastMouseX = mouse.x; |
| 3328 | + lastMouseX = mx; |
| 3341 | 3329 | |
| 3342 | 3330 | editor.ui.rightLoopPinMoving = true; |
| 3343 | 3331 | return; |
| @@ -3345,9 +3333,10 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) · 1 unmodified line |
| 3345 | 3333 | } |
| 3346 | 3334 | |
| 3347 | 3335 | // 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); |
| 3351 | 3340 | } |
| 3352 | 3341 | else if (mouse.rightButtonPressed) |
| 3353 | 3342 | { |
| @@ -3365,33 +3354,31 @@ void handleSampleDataMouseDown(bool mouseButtonHeld) · 11 unmodified lines |
| 3365 | 3354 | return; |
| 3366 | 3355 | } |
| 3367 | 3356 | |
| 3368 | | − if (mouse.x != lastMouseX) |
| 3357 | + if (mx != lastMouseX) |
| 3369 | 3358 | { |
| 3370 | 3359 | if (mouse.leftButtonPressed) |
| 3371 | 3360 | { |
| 3372 | 3361 | if (editor.ui.leftLoopPinMoving) |
| 3373 | 3362 | { |
| 3374 | | − lastMouseX = mouse.x; |
| 3375 | | − setLeftLoopPinPos(mouseXOffs + lastMouseX); |
| 3363 | + lastMouseX = mx; |
| 3364 | + setLeftLoopPinPos(mouseXOffs + mx); |
| 3376 | 3365 | } |
| 3377 | 3366 | else if (editor.ui.rightLoopPinMoving) |
| 3378 | 3367 | { |
| 3379 | | − lastMouseX = mouse.x; |
| 3380 | | − setRightLoopPinPos(mouseXOffs + lastMouseX); |
| 3368 | + lastMouseX = mx; |
| 3369 | + setRightLoopPinPos(mouseXOffs + mx); |
| 3381 | 3370 | } |
| 3382 | 3371 | else if (editor.ui.sampleDataOrLoopDrag >= 0) |
| 3383 | 3372 | { |
| 3384 | 3373 | // mark data |
| 3374 | + lastMouseX = mx; |
| 3385 | 3375 | |
| 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); |
| 3391 | 3378 | else if (lastMouseX == editor.ui.sampleDataOrLoopDrag) |
| 3392 | 3379 | 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); |
| 3395 | 3382 | } |
| 3396 | 3383 | } |
| 3397 | 3384 | } |