[xiph-cvs] cvs commit: win32-tools/oggdrop Script.rc encthread.c main.c resource.h
Chris Wolf
cwolf at xiph.org
Fri Sep 28 08:19:07 PDT 2001
cwolf 01/09/28 08:19:07
Modified: oggdrop Script.rc encthread.c main.c resource.h
Log:
Olaf van der Spek: Use registry to remember settings between sessions;
improve animation.
Revision Changes Path
1.7 +8 -8 win32-tools/oggdrop/Script.rc
Index: Script.rc
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/Script.rc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Script.rc 2001/09/12 19:38:56 1.6
+++ Script.rc 2001/09/28 15:19:06 1.7
@@ -26,7 +26,7 @@
// Bitmap
//
-IDB_TF12 BITMAP DISCARDABLE "resource/twirlfish12.bmp"
+IDB_TF01 BITMAP DISCARDABLE "resource/twirlfish01.bmp"
IDB_TF02 BITMAP DISCARDABLE "resource/twirlfish02.bmp"
IDB_TF03 BITMAP DISCARDABLE "resource/twirlfish03.bmp"
IDB_TF04 BITMAP DISCARDABLE "resource/twirlfish04.bmp"
@@ -37,7 +37,7 @@
IDB_TF09 BITMAP DISCARDABLE "resource/twirlfish09.bmp"
IDB_TF10 BITMAP DISCARDABLE "resource/twirlfish10.bmp"
IDB_TF11 BITMAP DISCARDABLE "resource/twirlfish11.bmp"
-IDB_TF01 BITMAP DISCARDABLE "resource/twirlfish01.bmp"
+IDB_TF12 BITMAP DISCARDABLE "resource/twirlfish12.bmp"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
@@ -45,18 +45,18 @@
// TEXTINCLUDE
//
-1 TEXTINCLUDE DISCARDABLE
+1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
-2 TEXTINCLUDE DISCARDABLE
+2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
-3 TEXTINCLUDE DISCARDABLE
+3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
@@ -70,7 +70,7 @@
// Menu
//
-IDR_MENU1 MENU DISCARDABLE
+IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "Menu"
BEGIN
@@ -89,9 +89,9 @@
BEGIN
MENUITEM "&Errors to log file", IDM_LOGERR
END
- MENUITEM "Always On Top", IDM_ONTOP
+ MENUITEM "Always on &Top", IDM_ONTOP
MENUITEM SEPARATOR
- MENUITEM "E&xit\tAlt+F4", IDM_QUIT
+ MENUITEM "E&xit\tAlt+F4", IDM_QUIT
END
MENUITEM SEPARATOR
END
1.5 +12 -9 win32-tools/oggdrop/encthread.c
Index: encthread.c
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/encthread.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- encthread.c 2001/08/12 20:18:02 1.4
+++ encthread.c 2001/09/28 15:19:06 1.5
@@ -1,5 +1,7 @@
#include <windows.h>
#include <time.h>
+#include <string.h>
+
#include "audio.h"
#include "encode.h"
@@ -53,8 +55,6 @@
if (file == NULL) return;
- EnterCriticalSection(&mutex);
-
// create entry
filename = strdup(file);
entry = (enclist_t *)malloc(sizeof(enclist_t));
@@ -62,20 +62,20 @@
entry->filename = filename;
entry->next = NULL;
+ EnterCriticalSection(&mutex);
+
// insert entry
if (head == NULL) {
head = entry;
- numfiles++;
- totalfiles++;
} else {
node = head;
while (node->next != NULL)
node = node->next;
node->next = entry;
- numfiles++;
- totalfiles++;
}
+ numfiles++;
+ totalfiles++;
LeaveCriticalSection(&mutex);
}
@@ -175,7 +175,7 @@
char *start, *end;
start = in_file;
- end = rindex(in_file, '.');
+ end = strrchr(in_file, '.');
end = end?end:(start + strlen(in_file)+1);
out_fn = (char *)malloc(end - start + 5);
@@ -185,6 +185,7 @@
}
/* Now, we need to select an input audio format */
+
while (formats[j].open_func) {
if (formats[j].open_func(in, &enc_opts)) {
foundformat = 1;
@@ -211,8 +212,8 @@
enc_opts.out = out;
enc_opts.comments = &vc;
enc_opts.filename = out_fn;
- enc_opts.bitrate = opt.kbps; /* defaulted at the start, so this is ok */
-
+ /* enc_opts.bitrate = opt.kbps; /* defaulted at the start, so this is ok */
+ enc_opts.bitrate = opt.kbps * enc_opts.channels / 2; /* Olaf: Scale to match channel count */
if (!enc_opts.total_samples_per_channel)
enc_opts.progress_update = _nothing_prog;
@@ -235,9 +236,11 @@
Sleep(500);
}
+ /* Olaf: We already reset these a few lines above
animate = 0;
totalfiles = 0;
numfiles = 0;
+ */
DeleteCriticalSection(&mutex);
1.6 +90 -116 win32-tools/oggdrop/main.c
Index: main.c
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/main.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- main.c 2001/08/30 16:44:49 1.5
+++ main.c 2001/09/28 15:19:06 1.6
@@ -9,6 +9,8 @@
#define LOSHORT(l) ((SHORT)(l))
#define HISHORT(l) ((SHORT)(((DWORD)(l) >> 16) & 0xFFFF))
+#define BASEKEY "Software\\Xiphophorus\\Oggdrop"
+
HANDLE event = NULL;
int width = 120, height = 120;
RECT bar1, bar2;
@@ -18,7 +20,6 @@
HINSTANCE hinst;
int frame = 0;
HBITMAP hbm[12], temp;
-HDC offscreen;
HMENU menu;
int encoding_done = 0;
double file_complete;
@@ -27,13 +28,72 @@
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int animate = 0;
+int get_base_key(HKEY* key)
+{
+ DWORD disposition;
+ return ERROR_SUCCESS != RegCreateKeyEx(HKEY_CURRENT_USER,
+ BASEKEY, 0, 0, 0, KEY_ALL_ACCESS, 0, key, &disposition);
+}
+
+int read_setting(const char* name, int default_value)
+{
+ HKEY base_key;
+ if (!get_base_key(&base_key))
+ {
+ int value;
+ DWORD cb_value = sizeof(int);
+ if (ERROR_SUCCESS == RegQueryValueEx(base_key, name, NULL, NULL,
+ (byte*)&value, &cb_value))
+ return value;
+ }
+ return default_value;
+}
+
+void write_setting(const char* name, int value)
+{
+ HKEY base_key;
+ if (!get_base_key(&base_key))
+ RegSetValueEx(base_key, name, 0, REG_DWORD, (byte*)&value, sizeof(int));
+}
+
+void set_bitrate(int v)
+{
+ CheckMenuItem(menu, IDM_BITRATE64, v == 64 ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(menu, IDM_BITRATE80, v == 80 ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(menu, IDM_BITRATE96, v == 96 ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(menu, IDM_BITRATE128, v == 128 ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(menu, IDM_BITRATE160, v == 160 ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(menu, IDM_BITRATE192, v == 192 ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(menu, IDM_BITRATE256, v == 256 ? MF_CHECKED : MF_UNCHECKED);
+ CheckMenuItem(menu, IDM_BITRATE350, v == 350 ? MF_CHECKED : MF_UNCHECKED);
+ encthread_setbitrate(v);
+ write_setting("bitrate", v);
+}
+void set_always_on_top(HWND hwnd, int v)
+{
+ CheckMenuItem(menu, IDM_ONTOP, v ? MF_CHECKED : MF_UNCHECKED);
+ SetWindowPos(hwnd, v ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOMOVE);
+ write_setting("always_on_top", v);
+}
+
+void set_logerr(HWND hwnd, int v)
+{
+ CheckMenuItem(menu, IDM_LOGERR, v ? MF_CHECKED : MF_UNCHECKED);
+ set_use_dialogs(v);
+ write_setting("logerr", v);
+}
+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
- static char szAppName[] = "oggdropWin";
+ static char szAppName[] = "oggdropWin";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
+ const int width = 120;
+ const int height = 120;
+ int x;
+ int y;
hinst = hInstance;
@@ -49,8 +109,11 @@
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
+
+ x = max(min(read_setting("window_x", 64), GetSystemMetrics(SM_CXSCREEN) - width), 0);
+ y = max(min(read_setting("window_y", 64), GetSystemMetrics(SM_CYSCREEN) - height), 0);
- hwnd = CreateWindow(szAppName, "oggdrop", WS_POPUP | WS_DLGFRAME, CW_USEDEFAULT, CW_USEDEFAULT,
+ hwnd = CreateWindow(szAppName, "OggDrop", WS_POPUP | WS_DLGFRAME, x, y,
width, height, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
@@ -58,20 +121,12 @@
SetTimer(hwnd, 1, 80, NULL);
+ set_bitrate(read_setting("bitrate", 96));
+ set_always_on_top(hwnd, read_setting("always_on_top", 1));
+ set_logerr(hwnd, read_setting("logerr", 0));
- frame = 0;
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF01), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF02), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF03), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF04), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF05), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF06), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF07), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF08), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF09), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF10), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF11), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- hbm[frame++] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF12), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
+ for (frame = 0; frame < 12; frame++)
+ hbm[frame] = LoadImage(hinst, MAKEINTRESOURCE(IDB_TF01 + frame), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
frame = 0;
while (GetMessage(&msg, NULL, 0, 0)) {
@@ -123,7 +178,6 @@
HDC desktop;
HBITMAP hbitmap;
HANDLE hdrop;
- int state;
double percomp;
switch (message) {
@@ -174,16 +228,15 @@
return 0;
case WM_TIMER:
- if (animate) {
- frame++;
- if (frame >= 12) frame = 0;
- GetClientRect(hwnd, &rect);
- InvalidateRect(hwnd, &rect, FALSE);
+ if (animate || frame) {
+ frame--;
+ if (frame < 0)
+ frame += 12;
} else {
frame = 0;
- GetClientRect(hwnd, &rect);
- InvalidateRect(hwnd, &rect, FALSE);
}
+ GetClientRect(hwnd, &rect);
+ InvalidateRect(hwnd, &rect, FALSE);
return 0;
case WM_LBUTTONDOWN:
@@ -214,6 +267,8 @@
*/
ClientToScreen(hwnd, &point);
SetWindowPos(hwnd, 0, point.x - start.x, point.y - start.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
+ write_setting("window_x", point.x - start.x);
+ write_setting("window_y", point.y - start.y);
}
return 0;
@@ -237,122 +292,42 @@
encoding_done = 1;
PostQuitMessage(0);
break;
-
case IDM_ONTOP:
- state = GetMenuState(menu, LOWORD(wParam), MF_BYCOMMAND);
- if ((state & MF_CHECKED) == MF_CHECKED) {
- CheckMenuItem(menu, LOWORD(wParam), MF_UNCHECKED);
- SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOMOVE);
- } else {
- CheckMenuItem(menu, LOWORD(wParam), MF_CHECKED);
- SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOMOVE);
- }
- break;
-
+ set_always_on_top(hwnd, ~GetMenuState(menu, LOWORD(wParam), MF_BYCOMMAND) & MF_CHECKED);
+ break;
case IDM_LOGERR:
- state = GetMenuState(menu, LOWORD(wParam), MF_BYCOMMAND);
- if ((state & MF_CHECKED) == MF_CHECKED) {
- CheckMenuItem(menu, LOWORD(wParam), MF_UNCHECKED);
- set_use_dialogs(1);
- } else {
- CheckMenuItem(menu, LOWORD(wParam), MF_CHECKED);
- set_use_dialogs(0);
- }
+ set_logerr(hwnd, ~GetMenuState(menu, LOWORD(wParam), MF_BYCOMMAND) & MF_CHECKED);
break;
-
case IDM_BITRATE64:
- CheckMenuItem(menu, IDM_BITRATE64, MF_CHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_UNCHECKED);
+ set_bitrate(64);
encthread_setbitrate(64);
break;
-
case IDM_BITRATE80:
- CheckMenuItem(menu, IDM_BITRATE64, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_CHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_UNCHECKED);
+ set_bitrate(80);
encthread_setbitrate(80);
break;
-
case IDM_BITRATE96:
- CheckMenuItem(menu, IDM_BITRATE64, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_CHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_UNCHECKED);
+ set_bitrate(96);
encthread_setbitrate(96);
break;
-
case IDM_BITRATE128:
- CheckMenuItem(menu, IDM_BITRATE64, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_CHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_UNCHECKED);
+ set_bitrate(128);
encthread_setbitrate(128);
break;
-
case IDM_BITRATE160:
- CheckMenuItem(menu, IDM_BITRATE64, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_CHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_UNCHECKED);
+ set_bitrate(160);
encthread_setbitrate(160);
break;
-
case IDM_BITRATE192:
- CheckMenuItem(menu, IDM_BITRATE64, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_CHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_UNCHECKED);
+ set_bitrate(192);
encthread_setbitrate(192);
break;
-
case IDM_BITRATE256:
- CheckMenuItem(menu, IDM_BITRATE64, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_CHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_UNCHECKED);
+ set_bitrate(256);
encthread_setbitrate(256);
break;
-
case IDM_BITRATE350:
- CheckMenuItem(menu, IDM_BITRATE64, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE80, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE96, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE128, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE160, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE192, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE256, MF_UNCHECKED);
- CheckMenuItem(menu, IDM_BITRATE350, MF_CHECKED);
+ set_bitrate(350);
encthread_setbitrate(350);
break;
}
@@ -372,4 +347,3 @@
return DefWindowProc(hwnd, message, wParam, lParam);
}
-
1.5 +3 -3 win32-tools/oggdrop/resource.h
Index: resource.h
===================================================================
RCS file: /usr/local/cvsroot/win32-tools/oggdrop/resource.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- resource.h 2001/08/12 20:18:02 1.4
+++ resource.h 2001/09/28 15:19:07 1.5
@@ -2,7 +2,7 @@
// Microsoft Developer Studio generated include file.
// Used by Script.rc
//
-#define IDB_TF12 112
+#define IDB_TF01 112
#define IDB_TF02 113
#define IDB_TF03 114
#define IDB_TF04 115
@@ -13,7 +13,7 @@
#define IDB_TF09 120
#define IDB_TF10 121
#define IDB_TF11 122
-#define IDB_TF01 123
+#define IDB_TF12 123
#define IDR_MENU1 124
#define IDI_ICON1 130
#define IDM_QUIT 40005
@@ -29,7 +29,7 @@
#define IDM_LOGERR 40015
// Next default values for new objects
-//
+//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list