aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk/toneview.c14
-rw-r--r--tonedata/tonedata.c25
-rw-r--r--tonedata/tonedata.h26
-rw-r--r--win32/toneview.c54
-rw-r--r--win32/toneview.h3
5 files changed, 101 insertions, 21 deletions
diff --git a/gtk/toneview.c b/gtk/toneview.c
index cc63af3..614130b 100644
--- a/gtk/toneview.c
+++ b/gtk/toneview.c
@@ -12,8 +12,9 @@ static struct {
GtkWidget *label[6];
struct fmplayer_tonedata tonedata;
struct fmplayer_tonedata tonedata_n;
+ struct fmplayer_tonedata tonedata_n_disp;
char strbuf[FMPLAYER_TONEDATA_STR_SIZE];
- enum fmplayer_tonedata_format format;
+ enum fmplayer_tonedata_format format, format_disp;
bool normalize;
GtkClipboard *clipboard;
} g = {
@@ -40,9 +41,14 @@ gboolean tick_cb(GtkWidget *widget, GdkFrameClock *clock, gpointer ptr) {
if (g.normalize) {
tonedata_ch_normalize_tl(&g.tonedata_n.ch[c]);
}
- tonedata_ch_string(g.format, g.strbuf, &g.tonedata_n.ch[c], 0);
- gtk_label_set_text(GTK_LABEL(g.label[c]), g.strbuf);
+ if (g.format != g.format_disp ||
+ fmplayer_tonedata_channel_isequal(&g.tonedata_n.ch[c], &g.tonedata_n_disp.ch[c])) {
+ g.tonedata_n_disp.ch[c] = g.tonedata_n.ch[c];
+ tonedata_ch_string(g.format, g.strbuf, &g.tonedata_n.ch[c], 0);
+ gtk_label_set_text(GTK_LABEL(g.label[c]), g.strbuf);
+ }
}
+ g.format_disp = g.format;
return G_SOURCE_CONTINUE;
}
@@ -80,6 +86,7 @@ static void on_copy_clicked(GtkButton *button, gpointer ptr) {
void show_toneview(void) {
if (!g.tonewin) {
+ g.format_disp = -1;
g.tonewin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(g.tonewin), "FM Tone Viewer");
g_signal_connect(g.tonewin, "destroy", G_CALLBACK(on_destroy), 0);
@@ -91,6 +98,7 @@ void show_toneview(void) {
gtk_box_pack_start(GTK_BOX(ctrlbox), format, FALSE, TRUE, 0);
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(format), "PMD");
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(format), "FMP");
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(format), "VOPM");
gtk_combo_box_set_active(GTK_COMBO_BOX(format), g.format);
g_signal_connect(format, "changed", G_CALLBACK(on_format_changed), 0);
GtkWidget *normalizecheck = gtk_check_button_new_with_label("Normalize");
diff --git a/tonedata/tonedata.c b/tonedata/tonedata.c
index 0d5daa6..874047b 100644
--- a/tonedata/tonedata.c
+++ b/tonedata/tonedata.c
@@ -100,6 +100,31 @@ void tonedata_ch_string(
ch->alg, ch->fb
);
break;
+ case FMPLAYER_TONEDATA_FMT_VOPM:
+ snprintf(buf, FMPLAYER_TONEDATA_STR_SIZE,
+ "@:%d\n"
+ "LFO: 0 0 0 0 0\n"
+ "CH: 64 %3d %3d 0 0 120 0\n"
+ "M1:%3d %3d %3d %3d %3d %3d %3d %3d %3d 0 0\n"
+ "C1:%3d %3d %3d %3d %3d %3d %3d %3d %3d 0 0\n"
+ "M2:%3d %3d %3d %3d %3d %3d %3d %3d %3d 0 0\n"
+ "C2:%3d %3d %3d %3d %3d %3d %3d %3d %3d 0 0",
+ tonenum,
+ ch->fb, ch->alg,
+ ch->slot[0].ar, ch->slot[0].dr, ch->slot[0].sr, ch->slot[0].rr,
+ ch->slot[0].sl, ch->slot[0].tl, ch->slot[0].ks, ch->slot[0].ml,
+ ch->slot[0].dt,
+ ch->slot[1].ar, ch->slot[1].dr, ch->slot[1].sr, ch->slot[1].rr,
+ ch->slot[1].sl, ch->slot[1].tl, ch->slot[1].ks, ch->slot[1].ml,
+ ch->slot[1].dt,
+ ch->slot[2].ar, ch->slot[2].dr, ch->slot[2].sr, ch->slot[2].rr,
+ ch->slot[2].sl, ch->slot[2].tl, ch->slot[2].ks, ch->slot[2].ml,
+ ch->slot[2].dt,
+ ch->slot[3].ar, ch->slot[3].dr, ch->slot[3].sr, ch->slot[3].rr,
+ ch->slot[3].sl, ch->slot[3].tl, ch->slot[3].ks, ch->slot[3].ml,
+ ch->slot[3].dt
+ );
+ break;
default:
buf[0] = 0;
break;
diff --git a/tonedata/tonedata.h b/tonedata/tonedata.h
index c8dd03c..5a7cd12 100644
--- a/tonedata/tonedata.h
+++ b/tonedata/tonedata.h
@@ -2,6 +2,7 @@
#define MYON_FMPLAYER_TONEDATA_H_INCLUDED
#include <stdint.h>
+#include <stdbool.h>
struct fmplayer_tonedata {
struct fmplayer_tonedata_channel {
@@ -22,6 +23,28 @@ struct fmplayer_tonedata {
} ch[6];
};
+static inline bool fmplayer_tonedata_channel_isequal(
+ const struct fmplayer_tonedata_channel *a,
+ const struct fmplayer_tonedata_channel *b) {
+ if (a->fb != b->fb) return false;
+ if (a->alg != b->alg) return false;
+ for (int s = 0; s < 4; s++) {
+ const struct fmplayer_tonedata_slot *sa = &a->slot[s];
+ const struct fmplayer_tonedata_slot *sb = &b->slot[s];
+ if (sa->ar != sb->ar) return false;
+ if (sa->dr != sb->dr) return false;
+ if (sa->sr != sb->sr) return false;
+ if (sa->rr != sb->rr) return false;
+ if (sa->sl != sb->sl) return false;
+ if (sa->tl != sb->tl) return false;
+ if (sa->ks != sb->ks) return false;
+ if (sa->ml != sb->ml) return false;
+ if (sa->dt != sb->dt) return false;
+ if (sa->ams != sb->ams) return false;
+ }
+ return true;
+}
+
struct opna;
void tonedata_from_opna(
struct fmplayer_tonedata *tonedata,
@@ -30,7 +53,8 @@ void tonedata_from_opna(
enum fmplayer_tonedata_format {
FMPLAYER_TONEDATA_FMT_PMD,
- FMPLAYER_TONEDATA_FMT_FMP
+ FMPLAYER_TONEDATA_FMT_FMP,
+ FMPLAYER_TONEDATA_FMT_VOPM,
};
enum {
diff --git a/win32/toneview.c b/win32/toneview.c
index adda8b6..ab0b3df 100644
--- a/win32/toneview.c
+++ b/win32/toneview.c
@@ -24,21 +24,25 @@ struct toneview_g toneview_g = {
static struct {
HINSTANCE hinst;
HWND toneviewer;
- HWND tonelabel[6];
+ HWND tonelabel[6], copybutton[6];
ATOM toneviewer_class;
struct fmplayer_tonedata tonedata;
struct fmplayer_tonedata tonedata_n;
+ struct fmplayer_tonedata tonedata_n_disp;
char strbuf[FMPLAYER_TONEDATA_STR_SIZE];
wchar_t strbuf_w[FMPLAYER_TONEDATA_STR_SIZE];
- enum fmplayer_tonedata_format format;
+ enum fmplayer_tonedata_format format, format_disp;
bool normalize;
HFONT font;
HFONT font_mono;
HWND checkbox;
HWND formatlist;
WNDPROC static_defproc;
+ void (*closecb)(void *ptr);
+ void *cbptr;
} g = {
- .normalize = true
+ .normalize = true,
+ .format_disp = -1
};
extern HWND g_currentdlg;
@@ -46,10 +50,14 @@ extern HWND g_currentdlg;
static void on_destroy(HWND hwnd) {
for (int i = 0; i < 6; i++) {
DestroyWindow(g.tonelabel[i]);
+ DestroyWindow(g.copybutton[i]);
}
DestroyWindow(g.checkbox);
DestroyWindow(g.formatlist);
g.toneviewer = 0;
+ if (g.closecb) {
+ g.closecb(g.cbptr);
+ }
}
enum {
@@ -58,8 +66,8 @@ enum {
NORMALIZE_W = 200,
TOP_H = 25,
TONELABEL_X = 10,
- TONELABEL_H = 100,
- TONELABEL_W = 300,
+ TONELABEL_H = 120,
+ TONELABEL_W = 390,
COPY_X = TONELABEL_X + TONELABEL_W + 5,
COPY_W = 100,
WIN_H = 10 + TOP_H + 5 + TONELABEL_H*6 + 5*5 + 10,
@@ -125,6 +133,7 @@ static LRESULT static_wndproc(
}
static bool on_create(HWND hwnd, const CREATESTRUCT *cs) {
+ g.format_disp = -1;
RECT wr;
wr.left = 0;
wr.right = WIN_W;
@@ -157,7 +166,8 @@ static bool on_create(HWND hwnd, const CREATESTRUCT *cs) {
SetWindowFont(g.formatlist, g.font, TRUE);
ComboBox_AddString(g.formatlist, L"PMD");
ComboBox_AddString(g.formatlist, L"FMP");
- ComboBox_SetCurSel(g.formatlist, 0);
+ ComboBox_AddString(g.formatlist, L"VOPM");
+ ComboBox_SetCurSel(g.formatlist, g.format);
g.checkbox = CreateWindowEx(0, L"button",
L"&Normalize",
WS_CHILD | WS_VISIBLE | BS_CHECKBOX | WS_TABSTOP,
@@ -177,12 +187,12 @@ static bool on_create(HWND hwnd, const CREATESTRUCT *cs) {
SetWindowFont(g.tonelabel[i], g.font_mono, TRUE);
wchar_t text[] = L"Copy (& )";
text[7] = L'1' + i;
- HWND copybutton = CreateWindowEx(0, L"button",
+ g.copybutton[i] = CreateWindowEx(0, L"button",
text,
WS_VISIBLE | WS_CHILD | WS_TABSTOP,
COPY_X, 40 + (TONELABEL_H+5)*i, 100, TONELABEL_H,
hwnd, (HMENU)((intptr_t)(ID_COPY0+i)), g.hinst, 0);
- SetWindowFont(copybutton, g.font, TRUE);
+ SetWindowFont(g.copybutton[i], g.font, TRUE);
}
ShowWindow(hwnd, SW_SHOW);
SetTimer(hwnd, TIMER_UPDATE, 16, 0);
@@ -201,15 +211,18 @@ static void on_timer(HWND hwnd, UINT id) {
if (g.normalize) {
tonedata_ch_normalize_tl(&g.tonedata_n.ch[c]);
}
- tonedata_ch_string(g.format, g.strbuf, &g.tonedata_n.ch[c], 0);
- for (int i = 0; i < FMPLAYER_TONEDATA_STR_SIZE; i++) {
- g.strbuf_w[i] = g.strbuf[i];
+ if (g.format != g.format_disp ||
+ !fmplayer_tonedata_channel_isequal(&g.tonedata_n.ch[c], &g.tonedata_n_disp.ch[c])) {
+ g.tonedata_n_disp.ch[c] = g.tonedata_n.ch[c];
+ tonedata_ch_string(g.format, g.strbuf, &g.tonedata_n_disp.ch[c], 0);
+ for (int i = 0; i < FMPLAYER_TONEDATA_STR_SIZE; i++) {
+ g.strbuf_w[i] = g.strbuf[i];
+ }
+ DefWindowProc(g.tonelabel[c], WM_SETTEXT, 0, (LPARAM)g.strbuf_w);
+ InvalidateRect(g.tonelabel[c], 0, FALSE);
}
- DefWindowProc(g.tonelabel[c], WM_SETTEXT, 0, (LPARAM)g.strbuf_w);
- RedrawWindow(g.tonelabel[c], 0, 0, RDW_ERASE | RDW_INVALIDATE);
}
-// RedrawWindow(hwnd, 0, 0, RDW_ERASE | RDW_INVALIDATE | RDW_ALLCHILDREN);
- InvalidateRect(hwnd, 0, FALSE);
+ g.format_disp = g.format;
}
}
@@ -231,7 +244,9 @@ static LRESULT CALLBACK wndproc(
return DefWindowProc(hwnd, msg, wParam, lParam);
}
-void show_toneview(HINSTANCE hinst, HWND parent) {
+void toneview_open(HINSTANCE hinst, HWND parent, void (*closecb)(void *ptr), void *cbptr) {
+ g.closecb = closecb;
+ g.cbptr = cbptr;
g.hinst = hinst;
if (!g.toneviewer) {
if (!g.toneviewer_class) {
@@ -259,3 +274,10 @@ void show_toneview(HINSTANCE hinst, HWND parent) {
SetForegroundWindow(g.toneviewer);
}
}
+
+void toneview_close(void) {
+ if (g.toneviewer) {
+ g.closecb = 0;
+ DestroyWindow(g.toneviewer);
+ }
+}
diff --git a/win32/toneview.h b/win32/toneview.h
index 32f402b..4a8fc06 100644
--- a/win32/toneview.h
+++ b/win32/toneview.h
@@ -11,6 +11,7 @@ extern struct toneview_g {
atomic_flag flag;
} toneview_g;
-void show_toneview(HINSTANCE hinst, HWND parent);
+void toneview_open(HINSTANCE hinst, HWND parent, void (*closecb)(void *ptr), void *cbptr);
+void toneview_close(void);
#endif // MYON_FMPLAYER_WIN32_TONEVIEW_H_INCLUDED