annotate system/Init.cpp @ 174:f8cf055dbf34

* Restructure WavFileWriter a bit to permit writing from raw data as well as from an existing model
author Chris Cannam
date Tue, 03 Oct 2006 10:06:37 +0000
parents 4b2ea82fd0ed
children c7122e70f8ec
rev   line source
Chris@150 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@150 2
Chris@150 3 /*
Chris@150 4 Sonic Visualiser
Chris@150 5 An audio file viewer and annotation editor.
Chris@150 6 Centre for Digital Music, Queen Mary, University of London.
Chris@150 7 This file copyright 2006 Chris Cannam.
Chris@150 8
Chris@150 9 This program is free software; you can redistribute it and/or
Chris@150 10 modify it under the terms of the GNU General Public License as
Chris@150 11 published by the Free Software Foundation; either version 2 of the
Chris@150 12 License, or (at your option) any later version. See the file
Chris@150 13 COPYING included with this distribution for more information.
Chris@150 14 */
Chris@150 15
Chris@150 16 #include <QApplication>
Chris@150 17 #include <QFont>
Chris@150 18
Chris@150 19 #include <iostream>
Chris@150 20
Chris@150 21 #ifdef Q_WS_X11
Chris@150 22 #include <X11/Xlib.h>
Chris@150 23 #include <X11/Xutil.h>
Chris@150 24 #include <X11/Xatom.h>
Chris@150 25 #include <X11/SM/SMlib.h>
Chris@150 26
Chris@150 27 static int handle_x11_error(Display *dpy, XErrorEvent *err)
Chris@150 28 {
Chris@150 29 char errstr[256];
Chris@150 30 XGetErrorText(dpy, err->error_code, errstr, 256);
Chris@150 31 if (err->error_code != BadWindow) {
Chris@174 32 std::cerr << "Sonic Visualiser: X Error: "
Chris@150 33 << errstr << " " << int(err->error_code)
Chris@150 34 << "\nin major opcode: "
Chris@150 35 << int(err->request_code) << std::endl;
Chris@150 36 }
Chris@150 37 return 0;
Chris@150 38 }
Chris@150 39 #endif
Chris@150 40
Chris@150 41 #ifdef Q_WS_WIN32
Chris@150 42
Chris@150 43 #include <fcntl.h>
Chris@150 44
Chris@150 45 // Set default file open mode to binary
Chris@150 46 #undef _fmode
Chris@150 47 int _fmode = _O_BINARY;
Chris@150 48
Chris@150 49 void redirectStderr()
Chris@150 50 {
Chris@150 51 HANDLE stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
Chris@150 52 if (!stderrHandle) return;
Chris@150 53
Chris@150 54 AllocConsole();
Chris@150 55
Chris@150 56 CONSOLE_SCREEN_BUFFER_INFO info;
Chris@150 57 GetConsoleScreenBufferInfo(stderrHandle, &info);
Chris@150 58 info.dwSize.Y = 1000;
Chris@150 59 SetConsoleScreenBufferSize(stderrHandle, info.dwSize);
Chris@150 60
Chris@150 61 int h = _open_osfhandle((long)stderrHandle, _O_TEXT);
Chris@150 62 if (h) {
Chris@150 63 FILE *fd = _fdopen(h, "w");
Chris@150 64 if (fd) {
Chris@150 65 *stderr = *fd;
Chris@150 66 setvbuf(stderr, NULL, _IONBF, 0);
Chris@150 67 }
Chris@150 68 }
Chris@150 69 }
Chris@150 70
Chris@150 71 #endif
Chris@150 72
Chris@150 73 extern void svSystemSpecificInitialisation()
Chris@150 74 {
Chris@150 75 #ifdef Q_WS_X11
Chris@150 76 XSetErrorHandler(handle_x11_error);
Chris@150 77 #endif
Chris@150 78
Chris@150 79 #ifdef Q_WS_WIN32
Chris@150 80 redirectStderr();
Chris@150 81 QFont fn = qApp->font();
Chris@150 82 fn.setFamily("Tahoma");
Chris@150 83 qApp->setFont(fn);
Chris@150 84 #else
Chris@150 85 #ifdef Q_WS_X11
Chris@150 86 QFont fn = qApp->font();
Chris@150 87 fn.setPointSize(fn.pointSize() + 2);
Chris@150 88 qApp->setFont(fn);
Chris@150 89 #endif
Chris@150 90 #endif
Chris@150 91 }
Chris@150 92