|
1 | 1 | #include "ui/player/waveform.h" |
2 | 2 | #include "core/memory_guard.h" |
| 3 | +#include "core/logger.h" |
3 | 4 | #include "audio/engine.h" |
4 | 5 | #include "core/logic/quantize.h" |
5 | 6 | #include "rlgl.h" |
@@ -48,6 +49,32 @@ static int Waveform_Update(Component *base) { |
48 | 49 | bool inWaveform = (mouse.x >= wfLeft && mouse.x <= wfRight && |
49 | 50 | mouse.y >= wfY && mouse.y <= wfY + waveH); |
50 | 51 |
|
| 52 | + // AUTO RELOAD: If focused and buffer was evicted, reload it |
| 53 | + bool isInteracting = (inWaveform || r->State->IsPlaying || r->State->IsTouching); |
| 54 | + if (isInteracting) r->lastInteractionTime = GetTime(); |
| 55 | + |
| 56 | + if (r->cachedTrack && r->cachedTrack->DynamicWaveform == NULL && r->cachedTrack->DynamicWaveformLen > 0) { |
| 57 | + // Reload if we are interacting OR we are master |
| 58 | + if (isInteracting || r->State->IsMaster) { |
| 59 | + UNX_LOG_INFO("[WAVE] Reloading evicted buffer for Deck %c", r->ID == 0 ? 'A' : 'B'); |
| 60 | + RB_ReloadWaveform(r->cachedTrack->AnalyzePath, |
| 61 | + &r->cachedTrack->DynamicWaveform, |
| 62 | + &r->cachedTrack->DynamicWaveformLen, |
| 63 | + &r->cachedTrack->WaveformType); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + // AUTO EVICT: If idle and memory is low, clear buffer |
| 68 | + if (r->cachedTrack && r->cachedTrack->DynamicWaveform != NULL) { |
| 69 | + if (!isInteracting && !r->State->IsPlaying && !r->State->IsMaster) { |
| 70 | + if (MemoryGuard_GetLevel() >= MEM_MODE_LITE && (GetTime() - r->lastInteractionTime > 5.0)) { |
| 71 | + UNX_LOG_INFO("[WAVE] Evicting idle buffer for Deck %c to save RAM", r->ID == 0 ? 'A' : 'B'); |
| 72 | + free(r->cachedTrack->DynamicWaveform); |
| 73 | + r->cachedTrack->DynamicWaveform = NULL; |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
51 | 78 | // Zoom & Jog Interaction Logic |
52 | 79 | int gesture = GetGestureDetected(); |
53 | 80 | if (inWaveform) { |
@@ -86,7 +113,13 @@ static int Waveform_Update(Component *base) { |
86 | 113 |
|
87 | 114 | // Clamp the index |
88 | 115 | if (currentIndex < 0) currentIndex = 0; |
89 | | - if (currentIndex >= NUM_ZOOM_LEVELS) currentIndex = NUM_ZOOM_LEVELS - 1; |
| 116 | + |
| 117 | + int maxZoomIndex = NUM_ZOOM_LEVELS - 1; |
| 118 | + // ECO MODE: Limit maximum zoom out to prevent heavy rendering |
| 119 | + if (MemoryGuard_GetLevel() >= MEM_MODE_ECO) { |
| 120 | + maxZoomIndex = (NUM_ZOOM_LEVELS / 2) + 1; // Limit to mid-zoom |
| 121 | + } |
| 122 | + if (currentIndex > maxZoomIndex) currentIndex = maxZoomIndex; |
90 | 123 |
|
91 | 124 | r->State->ZoomScale = ZOOM_LEVELS[currentIndex]; |
92 | 125 |
|
@@ -815,4 +848,5 @@ void WaveformRenderer_Init(WaveformRenderer *r, int id, DeckState *state, |
815 | 848 | r->cachedTrack = NULL; |
816 | 849 | r->dynWfmFrames = 480; |
817 | 850 | r->lastMouseX = 0; |
| 851 | + r->lastInteractionTime = GetTime(); |
818 | 852 | } |
0 commit comments