forked from 0xtob/nitrotracker
-
Notifications
You must be signed in to change notification settings - Fork 10
(Preliminary) sample cursor (nt) #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
prayerie
wants to merge
7
commits into
NitrousTracker:new
Choose a base branch
from
prayerie:samplecursor-nt
base: new
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5233452
Sample cursor
prayerie 7d5c745
draw fix
prayerie 195a067
Wip sprite stuff
prayerie 4ff0449
WIP loop handles as sprites
prayerie d3c28b1
remove useless debug goto,fix loop handle pos
prayerie ac867e4
Fix buggy loop handle draw on zoom
prayerie ceaad84
a bit of cleanup
prayerie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -450,7 +450,6 @@ void onKeypress(u8 note) | |
|
|
||
| void onKeyrelease(void) | ||
| { | ||
| // stop cursor | ||
| } | ||
|
|
||
| void handleNoteStroke(u8 note) | ||
|
|
@@ -645,7 +644,7 @@ void handleSampleChange(const u16 newsample) | |
| return; | ||
| } | ||
|
|
||
| sampledisplay->setSample(smp); | ||
| sampledisplay->setSample(smp, newsample, lbinstruments->getidx()); | ||
| sampledisplay->hideLoopPoints(); | ||
| nssamplevolume->setValue( (smp->getVolume()+1)/4 ); | ||
| nspanning->setValue(smp->getPanning()/2); | ||
|
|
@@ -657,7 +656,8 @@ void handleSampleChange(const u16 newsample) | |
| else | ||
| rbg_sampleloop->setActive(0); | ||
|
|
||
| updateKeyLabels(); | ||
| if (fxkb->is_visible()) updateKeyLabels(); | ||
|
|
||
| if (!had_changes) setHasUnsavedChanges(false); | ||
| /* | ||
| printf("Selected:"); | ||
|
|
@@ -674,6 +674,11 @@ void handleSampleChange(const u16 newsample) | |
| */ | ||
| } | ||
|
|
||
| void handleCursorUpdate(u8 chn, u8 x, bool shouldHide) | ||
| { | ||
| bool hide = shouldHide || gui->hasOverlayWidget(SUB_SCREEN); | ||
| oamSub.oamMemory[chn].x = hide ? 199 : x-3; // can't hide sprites if we scale them, so let's just draw them offscreen | ||
| } | ||
|
|
||
| void volEnvSetInst(Instrument *inst) | ||
| { | ||
|
|
@@ -748,6 +753,21 @@ void updateTempoAndBpm(void) | |
| nbtempo->setValue(song->getTempo()); | ||
| } | ||
|
|
||
| void cursorTimerHandler(void) | ||
| { | ||
| sampledisplay->calcCursor(); | ||
| } | ||
|
|
||
| void startCursorTimer(void) | ||
| { | ||
| TIMER1_DATA = TIMER_FREQ_64(60); // Call handler every frame | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. per libnds |
||
| TIMER1_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_DIV_64; | ||
| irqSet(IRQ_TIMER1, cursorTimerHandler); | ||
| irqEnable(IRQ_TIMER1); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| void setSong(Song *newsong) | ||
| { | ||
| song = newsong; | ||
|
|
@@ -816,7 +836,7 @@ void setSong(Song *newsong) | |
|
|
||
| inst = song->getInstrument(state->instrument); | ||
| if(inst != NULL) { | ||
| sampledisplay->setSample(inst->getSample(state->sample)); | ||
| sampledisplay->setSample(inst->getSample(state->sample), state->sample, state->instrument); | ||
| } | ||
|
|
||
| strncpy(str, song->getName(), sizeof(str)-1); | ||
|
|
@@ -2163,6 +2183,17 @@ void destroyThemeDialog(void) | |
| redrawSubScreen(); | ||
| } | ||
|
|
||
| // TODO this is temp, all this stuff should be in sampledisplay | ||
| void setSpritePals(void) | ||
| { | ||
| *(SPRITE_PALETTE_SUB+1) = settings->getTheme()->col_sample_cursor; | ||
|
|
||
| // palette index 1 | ||
| *(SPRITE_PALETTE_SUB+2+16) = settings->getTheme()->col_outline; | ||
| *(SPRITE_PALETTE_SUB+3+16) = settings->getTheme()->col_loop; | ||
| *(SPRITE_PALETTE_SUB+1+16) = settings->getTheme()->col_loop; | ||
| } | ||
|
|
||
| void reloadSkin(void) | ||
| { | ||
| gui->setTheme(settings->getTheme(), settings->getTheme()->col_bg); | ||
|
|
@@ -2174,6 +2205,9 @@ void reloadSkin(void) | |
| u32 colcol = col | col << 16; | ||
| dmaFillWords(colcol, sub_vram + (256 * y) + 224, (256 - 224) * 2); | ||
| } | ||
|
|
||
| setSpritePals(); | ||
|
|
||
| gui->draw(); | ||
| redrawSubScreen(); | ||
| setRecordMode(state->recording); | ||
|
|
@@ -2963,7 +2997,7 @@ void sample_del_selection(void) | |
|
|
||
| DC_FlushAll(); | ||
|
|
||
| sampledisplay->setSample(smp); | ||
| sampledisplay->setSample(smp, state->sample, state->instrument); | ||
| setHasUnsavedChanges(true); | ||
| } | ||
|
|
||
|
|
@@ -2985,7 +3019,7 @@ void sample_fade_in(void) | |
|
|
||
| DC_FlushAll(); | ||
|
|
||
| sampledisplay->setSample(smp); | ||
| sampledisplay->setSample(smp, state->sample, state->instrument); | ||
| setHasUnsavedChanges(true); | ||
| } | ||
|
|
||
|
|
@@ -3007,7 +3041,7 @@ void sample_fade_out(void) | |
|
|
||
| DC_FlushAll(); | ||
|
|
||
| sampledisplay->setSample(smp); | ||
| sampledisplay->setSample(smp, state->sample, state->instrument); | ||
| setHasUnsavedChanges(true); | ||
| } | ||
|
|
||
|
|
@@ -3032,7 +3066,7 @@ void sample_reverse(void) | |
|
|
||
| DC_FlushAll(); | ||
|
|
||
| sampledisplay->setSample(smp); | ||
| sampledisplay->setSample(smp, state->sample, state->instrument); | ||
| setHasUnsavedChanges(true); | ||
| } | ||
|
|
||
|
|
@@ -3383,6 +3417,8 @@ void setupGUI(bool dldi_enabled) | |
| fxkb = new FXKeyboard(0, 152, (uint16*)CHAR_BASE_BLOCK_SUB(0), (uint16*)SCREEN_BASE_BLOCK_SUB(1/*8*/), &sub_vram, onFxKeyPressed, false); | ||
| fxkb->set_overdraw(false); | ||
|
|
||
| setSpritePals(); | ||
|
|
||
|
|
||
| pixmaplogo = new GradientIcon(98, 1, 80, 17, | ||
| (const u32*) nitrotracker_logo_raw, &sub_vram); | ||
|
|
@@ -4275,6 +4311,9 @@ void VblankHandler(void) | |
| fastscroll = false; | ||
| } | ||
|
|
||
| oamUpdate(&oamSub); | ||
|
|
||
|
|
||
| // Easy Piano pak handling logic | ||
| if (pianoIsInserted()) | ||
| { | ||
|
|
@@ -4428,10 +4467,11 @@ int main(int argc, char **argv) { | |
| videoSetMode(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG2_ACTIVE); | ||
|
|
||
| // Sub screen: Keyboard tiles, Typewriter tiles and ERB | ||
| videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE); | ||
| videoSetModeSub(MODE_5_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG1_ACTIVE | DISPLAY_BG2_ACTIVE | DISPLAY_SPR_ACTIVE | DISPLAY_SPR_1D); | ||
|
|
||
| vramSetPrimaryBanks(VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000, | ||
| VRAM_C_SUB_BG_0x06200000 , VRAM_D_LCD); | ||
| VRAM_C_SUB_BG_0x06200000 , VRAM_D_SUB_SPRITE); | ||
|
|
||
|
|
||
| // SUB_BG0 for Piano Tiles | ||
| videoBgEnableSub(0); | ||
|
|
@@ -4460,6 +4500,84 @@ int main(int argc, char **argv) { | |
| int sub_bg = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0); | ||
| bgSetPriority(sub_bg, 0); | ||
|
|
||
| oamInit(&oamSub, SpriteMapping_1D_32, false); | ||
|
|
||
| windowEnableSub(WINDOW_0); | ||
|
|
||
| bgWindowEnable(sub_bg, (WINDOW)(WINDOW_0|WINDOW_OUT)); | ||
| bgWindowEnable(piano_bg, (WINDOW)(WINDOW_0|WINDOW_OUT)); | ||
| bgWindowEnable(typewriter_bg, (WINDOW)(WINDOW_0|WINDOW_OUT)); | ||
|
|
||
| windowSetBoundsSub(WINDOW_0, 5, 24, 5+129, 23+61); // sampledisplay x1,y1,x2,y2 | ||
| oamWindowEnable(&oamSub, WINDOW_0); | ||
|
|
||
| u16 *gfxSampleCursor = oamAllocateGfx(&oamSub, SpriteSize_16x32, SpriteColorFormat_16Color); | ||
|
|
||
| u16 *gfxLoopHandles = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_16Color); | ||
|
|
||
| *(gfxSampleCursor+64)=1; | ||
|
|
||
| oamSub.oamRotationMemory[0].vdy = 0; // max y scale | ||
|
|
||
| for (int c=0;c<16;++c) | ||
| { | ||
| oamSet(&oamSub, c, 256, 23, 0, 0, | ||
| SpriteSize_16x32, | ||
| SpriteColorFormat_16Color, | ||
| gfxSampleCursor, | ||
| 0, true, false, false, false, false); | ||
| } | ||
|
|
||
| const unsigned int loophandleTiles[8] __attribute__((aligned(4)))= | ||
| { | ||
| 0x22000000, | ||
| 0x33200000, | ||
| 0x33320000, | ||
| 0x33332000, | ||
| 0x33333200, | ||
| 0x33333320, | ||
| 0x33333332, | ||
| 0x33333332 | ||
| }; | ||
|
|
||
| memcpy(gfxLoopHandles, loophandleTiles, 32); | ||
|
|
||
| // handles | ||
| for (int i=16;i<20;++i) | ||
| { | ||
| oamSet(&oamSub, i, | ||
| 50, 25, | ||
| 0, | ||
| 1, | ||
| SpriteSize_8x8, SpriteColorFormat_16Color, | ||
| gfxLoopHandles, | ||
| -1, | ||
| false, | ||
| false, | ||
| i % 2 == 1, i > 17, // h-flip every other handle, v-flip the last two handles | ||
| false); | ||
| } | ||
|
|
||
| // reuse cursors as part of the loop handles | ||
| for (int i=20;i<22;++i) | ||
| { | ||
| oamSet(&oamSub, i, | ||
| 50, 25, | ||
| 0, | ||
| 1, | ||
| SpriteSize_16x32, SpriteColorFormat_16Color, | ||
| gfxSampleCursor, | ||
| 0, | ||
| true, | ||
| false, | ||
| false, false, | ||
| false); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| //for (int i=0;i<16;++i) oamSetHidden(&oamSub, i, true); // using hide=true in oamSet makes the draw broken fsr | ||
|
|
||
| // Special effects | ||
| #ifdef DEBUG | ||
| REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG0 | BLEND_DST_BG2; | ||
|
|
@@ -4530,9 +4648,19 @@ int main(int argc, char **argv) { | |
| CommandSetSong(song); | ||
|
|
||
| setupGUI(fat_success); | ||
|
|
||
| startCursorTimer(); | ||
| SampleCursor *scursors = (SampleCursor*)ntxm_ccalloc(MAX_CHANNELS, sizeof(SampleCursor)); | ||
| CommandSetCursorPosPtr(scursors); | ||
| sampledisplay->setCursorPosPtr((SampleCursor*)memUncached(scursors)); | ||
| sampledisplay->setOnCursorUpdate(handleCursorUpdate); | ||
|
|
||
| action_buffer->register_change_callback({&actionBufferChangeCallback}); | ||
|
|
||
| applySettings(); | ||
|
|
||
|
|
||
|
|
||
| setSong(song); | ||
|
|
||
| #ifndef DEBUG | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
admittedly not much better than just doing this in vblank, although this results in less drift anyway. i tried calculating using ticks but couldn't get it as accurate