Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 138 additions & 10 deletions arm9/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ void onKeypress(u8 note)

void onKeyrelease(void)
{
// stop cursor
}

void handleNoteStroke(u8 note)
Expand Down Expand Up @@ -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);
Expand All @@ -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:");
Expand All @@ -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)
{
Expand Down Expand Up @@ -748,6 +753,21 @@ void updateTempoAndBpm(void)
nbtempo->setValue(song->getTempo());
}

void cursorTimerHandler(void)
{
sampledisplay->calcCursor();
Copy link
Copy Markdown
Collaborator Author

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

}

void startCursorTimer(void)
{
TIMER1_DATA = TIMER_FREQ_64(60); // Call handler every frame
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per libnds timers.h timer1 doesn't seem to be used for anything else so i presume it's ok

TIMER1_CR = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_DIV_64;
irqSet(IRQ_TIMER1, cursorTimerHandler);
irqEnable(IRQ_TIMER1);
}



void setSong(Song *newsong)
{
song = newsong;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -2963,7 +2997,7 @@ void sample_del_selection(void)

DC_FlushAll();

sampledisplay->setSample(smp);
sampledisplay->setSample(smp, state->sample, state->instrument);
setHasUnsavedChanges(true);
}

Expand All @@ -2985,7 +3019,7 @@ void sample_fade_in(void)

DC_FlushAll();

sampledisplay->setSample(smp);
sampledisplay->setSample(smp, state->sample, state->instrument);
setHasUnsavedChanges(true);
}

Expand All @@ -3007,7 +3041,7 @@ void sample_fade_out(void)

DC_FlushAll();

sampledisplay->setSample(smp);
sampledisplay->setSample(smp, state->sample, state->instrument);
setHasUnsavedChanges(true);
}

Expand All @@ -3032,7 +3066,7 @@ void sample_reverse(void)

DC_FlushAll();

sampledisplay->setSample(smp);
sampledisplay->setSample(smp, state->sample, state->instrument);
setHasUnsavedChanges(true);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -4275,6 +4311,9 @@ void VblankHandler(void)
fastscroll = false;
}

oamUpdate(&oamSub);


// Easy Piano pak handling logic
if (pianoIsInserted())
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading