Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
78 changes: 65 additions & 13 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,7 +674,6 @@ void handleSampleChange(const u16 newsample)
*/
}


void volEnvSetInst(Instrument *inst)
{
bool had_unsaved = state->unsaved_changes;
Expand Down Expand Up @@ -748,6 +747,21 @@ void updateTempoAndBpm(void)
nbtempo->setValue(song->getTempo());
}

void cursorTimerHandler(void)
{
sampledisplay->calcCursor();
Copy link
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
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 +830,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 +2177,7 @@ void destroyThemeDialog(void)
redrawSubScreen();
}


void reloadSkin(void)
{
gui->setTheme(settings->getTheme(), settings->getTheme()->col_bg);
Expand All @@ -2174,6 +2189,7 @@ void reloadSkin(void)
u32 colcol = col | col << 16;
dmaFillWords(colcol, sub_vram + (256 * y) + 224, (256 - 224) * 2);
}

gui->draw();
redrawSubScreen();
setRecordMode(state->recording);
Expand Down Expand Up @@ -2963,7 +2979,7 @@ void sample_del_selection(void)

DC_FlushAll();

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

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

DC_FlushAll();

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

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

DC_FlushAll();

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

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

DC_FlushAll();

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

Expand Down Expand Up @@ -3367,22 +3383,31 @@ void sampleDrawToggle(bool on)
sampledisplay->setDrawMode(on);
}

void handleOverlayWidgetChange(u8 screen, bool visible)
{
if (screen == SUB_SCREEN)
{
if (visible) oamDisable(&oamSub);
else oamEnable(&oamSub);
}
}

#define RIGHT_SIDE_BUTTON_WIDTH 30
#define RIGHT_SIDE_BUTTON_X 225

void setupGUI(bool dldi_enabled)
{
gui = new GUI();
gui->setTheme(settings->getTheme(), settings->getTheme()->col_bg);

gui->setOnOverlayChanged(handleOverlayWidgetChange);
kb = new Piano(0, 152, 224, 40, (uint16*)CHAR_BASE_BLOCK_SUB(0), (uint16*)SCREEN_BASE_BLOCK_SUB(1/*8*/), &sub_vram);
kb->set_overdraw(false);
kb->registerNoteCallback(handleNoteStroke);
kb->registerReleaseCallback(handleNoteRelease);

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);


pixmaplogo = new GradientIcon(98, 1, 80, 17,
(const u32*) nitrotracker_logo_raw, &sub_vram);
Expand Down Expand Up @@ -4275,6 +4300,9 @@ void VblankHandler(void)
fastscroll = false;
}

oamUpdate(&oamSub);


// Easy Piano pak handling logic
if (pianoIsInserted())
{
Expand Down Expand Up @@ -4428,10 +4456,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 +4489,20 @@ int main(int argc, char **argv) {
int sub_bg = bgInitSub(2, BgType_Bmp16, BgSize_B16_256x256, 2, 0);
bgSetPriority(sub_bg, 0);

// Sample display cursors and loop handles
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);



// Special effects
#ifdef DEBUG
REG_BLDCNT = BLEND_ALPHA | BLEND_SRC_BG0 | BLEND_DST_BG2;
Expand Down Expand Up @@ -4530,9 +4573,18 @@ 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));

action_buffer->register_change_callback({&actionBufferChangeCallback});

applySettings();



setSong(song);

#ifndef DEBUG
Expand Down
Loading
Loading