From a4e3734568ae9fd617d548fa099046935b212f18 Mon Sep 17 00:00:00 2001 From: Wirlaburla Date: Wed, 20 Mar 2024 19:07:36 -0500 Subject: [PATCH] replace channel bar page with scope/waveform --- aur/PKGBUILD | 2 +- src/main.cpp | 46 +++++++++++++++++++++++++++------------------- src/trakker.h | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/aur/PKGBUILD b/aur/PKGBUILD index 8a40066..b4a0eba 100644 --- a/aur/PKGBUILD +++ b/aur/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Nick G. pkgname=trakker-git -pkgver=0.5.1 +pkgver=0.5.2.r3.gf97e506 pkgrel=1 pkgdesc='A terminal-based tracker interface for libxmp.' arch=('x86_64') diff --git a/src/main.cpp b/src/main.cpp index c1fed61..e4ccee1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ #define BUFFER_SIZE 250000 static std::string note_name[] = { "C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B " }; -static std::string pages[] = { "1. Info", "2. Pattern", "3. Bars", "4. Piano Roll", "5. Config", "6. Help" }; +static std::string pages[] = { "1. Info", "2. Pattern", "3. Scope", "4. Piano Roll", "5. Config", "6. Help" }; static char* device = "default"; char* file; @@ -437,7 +437,7 @@ void displayHeader(xmp_module_info *mi, xmp_frame_info *fi) { } else if (display == 1) { displayPatterns(mi, fi); } else if (display == 2) { - displayVolumes(mi, fi); + displayScope(mi, fi); } else if (display == 3) { displayNoteRoll(mi, fi); } else if (display == 4) { @@ -599,23 +599,31 @@ void displayPatterns(xmp_module_info *mi, xmp_frame_info *fi) { } } -void displayVolumes(xmp_module_info *mi, xmp_frame_info *fi) { - int chns = mi->mod->chn; - chtype no_pair = COLOR_PAIR(5); - for (int y = vOffset; y < chns; y++) { - if (y > (LINES - 4)+vOffset || y < 0) continue; - struct xmp_channel_info cinfo = fi->channel_info[y]; - if (y > (LINES - 3)+vOffset) break; - wmove(dis, y-vOffset, 0); - int cvol = (cinfo.volume * (COLS - 5)) / (64 * (vol / 100)); - wattron(dis, no_pair); - wprintw(dis, "%02X", y); - wattroff(dis, no_pair); - for (int c = 0; c < COLS - 5; c++) { - if (c < cvol) waddstr(dis, "#"); - else waddstr(dis, " "); - } - } +int lerp (int a, int b, float f) { + return a + f * (b - a); +} + +#include +std::vector bufbuf; +void displayScope(xmp_module_info *mi, xmp_frame_info *fi) { + bufbuf.resize(fi->buffer_size); + const char* xbuf = (char*)fi->buffer; + float nxcol = 0; + int rate = 2; + int midLine = (LINES-4)/2; + int horzInc = 1; + for (int s = 0; s < fi->buffer_size; s++) { + if (nxcol >= COLS-2) break; + int l = lerp(bufbuf[s], xbuf[s], 0.2f); + int newpos = ((l+0x80) * (LINES - 4)) / 0xFF; + horzInc = (newpos < midLine)?-1:1; + for (int j = midLine; j != newpos; j+=horzInc) { + wmove(dis, j, (int)nxcol); + waddch(dis, '|'); + } + nxcol+=(1.0*(COLS-2)/fi->buffer_size); + bufbuf[s] = l; + } } void displayNoteRoll(xmp_module_info *mi, xmp_frame_info *fi) { diff --git a/src/trakker.h b/src/trakker.h index a216924..570aded 100644 --- a/src/trakker.h +++ b/src/trakker.h @@ -12,7 +12,7 @@ void createWindows(); void displayHeader(xmp_module_info *mi, xmp_frame_info *fi); void displayInfo(xmp_module_info *mi, xmp_frame_info *fi); void displayPatterns(xmp_module_info *mi, xmp_frame_info *fi); -void displayVolumes(xmp_module_info *mi, xmp_frame_info *fi); +void displayScope(xmp_module_info *mi, xmp_frame_info *fi); void displayNoteRoll(xmp_module_info *mi, xmp_frame_info *fi); void displayPlayer(); void displayHelp();