| 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| 4 | * |
|---|
| 5 | * http://www.hydrogen-music.org |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY, without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #include <QtGui> |
|---|
| 24 | #include "config.h" |
|---|
| 25 | #include "version.h" |
|---|
| 26 | #include <getopt.h> |
|---|
| 27 | |
|---|
| 28 | #include "SplashScreen.h" |
|---|
| 29 | #include "HydrogenApp.h" |
|---|
| 30 | #include "MainForm.h" |
|---|
| 31 | |
|---|
| 32 | #ifdef LASH_SUPPORT |
|---|
| 33 | #include <hydrogen/LashClient.h> |
|---|
| 34 | #endif |
|---|
| 35 | |
|---|
| 36 | #include <hydrogen/midiMap.h> |
|---|
| 37 | #include <hydrogen/audio_engine.h> |
|---|
| 38 | #include <hydrogen/hydrogen.h> |
|---|
| 39 | #include <hydrogen/globals.h> |
|---|
| 40 | #include <hydrogen/event_queue.h> |
|---|
| 41 | #include <hydrogen/Preferences.h> |
|---|
| 42 | #include <hydrogen/data_path.h> |
|---|
| 43 | #include <hydrogen/h2_exception.h> |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | #include <iostream> |
|---|
| 47 | using namespace std; |
|---|
| 48 | |
|---|
| 49 | void showInfo(); |
|---|
| 50 | void showUsage(); |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | #define HAS_ARG 1 |
|---|
| 54 | static struct option long_opts[] = { |
|---|
| 55 | {"driver", HAS_ARG, NULL, 'd'}, |
|---|
| 56 | {"song", HAS_ARG, NULL, 's'}, |
|---|
| 57 | {"version", 0, NULL, 'v'}, |
|---|
| 58 | {"nosplash", 0, NULL, 'n'}, |
|---|
| 59 | {"verbose", 0, NULL, 'V'}, |
|---|
| 60 | {"help", 0, NULL, 'h'}, |
|---|
| 61 | {0, 0, 0, 0}, |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | #define NELEM(a) ( sizeof(a)/sizeof((a)[0]) ) |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | // |
|---|
| 68 | // Set the palette used in the application |
|---|
| 69 | // |
|---|
| 70 | void setPalette( QApplication *pQApp ) |
|---|
| 71 | { |
|---|
| 72 | // create the default palette |
|---|
| 73 | QPalette defaultPalette; |
|---|
| 74 | |
|---|
| 75 | // A general background color. |
|---|
| 76 | defaultPalette.setColor( QPalette::Background, QColor( 58, 62, 72 ) ); |
|---|
| 77 | |
|---|
| 78 | // A general foreground color. |
|---|
| 79 | defaultPalette.setColor( QPalette::Foreground, QColor( 255, 255, 255 ) ); |
|---|
| 80 | |
|---|
| 81 | // Used as the background color for text entry widgets; usually white or another light color. |
|---|
| 82 | defaultPalette.setColor( QPalette::Base, QColor( 88, 94, 112 ) ); |
|---|
| 83 | |
|---|
| 84 | // Used as the alternate background color in views with alternating row colors |
|---|
| 85 | defaultPalette.setColor( QPalette::AlternateBase, QColor( 138, 144, 162 ) ); |
|---|
| 86 | |
|---|
| 87 | // The foreground color used with Base. This is usually the same as the Foreground, in which case it must provide good contrast with Background and Base. |
|---|
| 88 | defaultPalette.setColor( QPalette::Text, QColor( 255, 255, 255 ) ); |
|---|
| 89 | |
|---|
| 90 | // The general button background color. This background can be different from Background as some styles require a different background color for buttons. |
|---|
| 91 | defaultPalette.setColor( QPalette::Button, QColor( 88, 94, 112 ) ); |
|---|
| 92 | |
|---|
| 93 | // A foreground color used with the Button color. |
|---|
| 94 | defaultPalette.setColor( QPalette::ButtonText, QColor( 255, 255, 255 ) ); |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | // Lighter than Button color. |
|---|
| 98 | defaultPalette.setColor( QPalette::Light, QColor( 138, 144, 162 ) ); |
|---|
| 99 | |
|---|
| 100 | // Between Button and Light. |
|---|
| 101 | defaultPalette.setColor( QPalette::Midlight, QColor( 128, 134, 152 ) ); |
|---|
| 102 | |
|---|
| 103 | // Darker than Button. |
|---|
| 104 | defaultPalette.setColor( QPalette::Dark, QColor( 58, 62, 72 ) ); |
|---|
| 105 | |
|---|
| 106 | // Between Button and Dark. |
|---|
| 107 | defaultPalette.setColor( QPalette::Mid, QColor( 81, 86, 99 ) ); |
|---|
| 108 | |
|---|
| 109 | // A very dark color. By default, the shadow color is Qt::black. |
|---|
| 110 | defaultPalette.setColor( QPalette::Shadow, QColor( 255, 255, 255 ) ); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | // A color to indicate a selected item or the current item. |
|---|
| 114 | defaultPalette.setColor( QPalette::Highlight, QColor( 116, 124, 149 ) ); |
|---|
| 115 | |
|---|
| 116 | // A text color that contrasts with Highlight. |
|---|
| 117 | defaultPalette.setColor( QPalette::HighlightedText, QColor( 255, 255, 255 ) ); |
|---|
| 118 | |
|---|
| 119 | pQApp->setPalette( defaultPalette ); |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | int main(int argc, char *argv[]) |
|---|
| 126 | { |
|---|
| 127 | try { |
|---|
| 128 | |
|---|
| 129 | QString songFilename = ""; |
|---|
| 130 | bool bNoSplash = false; |
|---|
| 131 | QString sSelectedDriver = ""; |
|---|
| 132 | |
|---|
| 133 | #ifdef CONFIG_DEBUG |
|---|
| 134 | Object::use_verbose_log( true ); |
|---|
| 135 | #endif |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | // Options... |
|---|
| 140 | char *cp; |
|---|
| 141 | struct option *op; |
|---|
| 142 | char opts[NELEM(long_opts) * 2 + 1]; |
|---|
| 143 | |
|---|
| 144 | // Build up the short option QString |
|---|
| 145 | cp = opts; |
|---|
| 146 | for (op = long_opts; op < &long_opts[NELEM(long_opts)]; op++) { |
|---|
| 147 | *cp++ = op->val; |
|---|
| 148 | if (op->has_arg) |
|---|
| 149 | *cp++ = ':'; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | QApplication* pQApp = new QApplication(argc, argv); |
|---|
| 153 | |
|---|
| 154 | // Deal with the options |
|---|
| 155 | int c; |
|---|
| 156 | for (;;) { |
|---|
| 157 | c = getopt_long(argc, argv, opts, long_opts, NULL); |
|---|
| 158 | if (c == -1) |
|---|
| 159 | break; |
|---|
| 160 | |
|---|
| 161 | switch(c) { |
|---|
| 162 | case 'd': |
|---|
| 163 | sSelectedDriver = optarg; |
|---|
| 164 | break; |
|---|
| 165 | |
|---|
| 166 | case 's': |
|---|
| 167 | songFilename = optarg; |
|---|
| 168 | break; |
|---|
| 169 | |
|---|
| 170 | case 'v': |
|---|
| 171 | std::cout << VERSION << std::endl; |
|---|
| 172 | exit(0); |
|---|
| 173 | break; |
|---|
| 174 | |
|---|
| 175 | case 'V': |
|---|
| 176 | Object::use_verbose_log( true ); |
|---|
| 177 | break; |
|---|
| 178 | |
|---|
| 179 | case 'n': |
|---|
| 180 | bNoSplash = true; |
|---|
| 181 | break; |
|---|
| 182 | |
|---|
| 183 | case 'h': |
|---|
| 184 | case '?': |
|---|
| 185 | showInfo(); |
|---|
| 186 | showUsage(); |
|---|
| 187 | exit(0); |
|---|
| 188 | break; |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | showInfo(); |
|---|
| 193 | |
|---|
| 194 | _INFOLOG( QString("Using QT version ") + QString( qVersion() ) ); |
|---|
| 195 | _INFOLOG( "Using data path: " + H2Core::DataPath::get_data_path() ); |
|---|
| 196 | |
|---|
| 197 | H2Core::Preferences *pPref = H2Core::Preferences::getInstance(); |
|---|
| 198 | |
|---|
| 199 | #ifdef LASH_SUPPORT |
|---|
| 200 | |
|---|
| 201 | LashClient *lashClient = new LashClient("hydrogen", "Hydrogen", &argc, &argv); |
|---|
| 202 | |
|---|
| 203 | #endif |
|---|
| 204 | if (sSelectedDriver == "auto") { |
|---|
| 205 | pPref->m_sAudioDriver = "Auto"; |
|---|
| 206 | } |
|---|
| 207 | else if (sSelectedDriver == "jack") { |
|---|
| 208 | pPref->m_sAudioDriver = "Jack"; |
|---|
| 209 | } |
|---|
| 210 | else if ( sSelectedDriver == "oss" ) { |
|---|
| 211 | pPref->m_sAudioDriver = "Oss"; |
|---|
| 212 | } |
|---|
| 213 | else if ( sSelectedDriver == "alsa" ) { |
|---|
| 214 | pPref->m_sAudioDriver = "Alsa"; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | QString family = pPref->getApplicationFontFamily(); |
|---|
| 218 | pQApp->setFont( QFont( family, pPref->getApplicationFontPointSize() ) ); |
|---|
| 219 | |
|---|
| 220 | QTranslator tor( 0 ); |
|---|
| 221 | QString sTranslationFile = QString("hydrogen.") + QLocale::system().name(); |
|---|
| 222 | QString sLocale = QLocale::system().name(); |
|---|
| 223 | if ( sLocale != "C") { |
|---|
| 224 | QString sTranslationPath = "data/i18n"; |
|---|
| 225 | QString total = sTranslationPath + "/" + sTranslationFile + ".qm"; |
|---|
| 226 | |
|---|
| 227 | bool bTransOk = tor.load( total, "." ); |
|---|
| 228 | if ( bTransOk ) { |
|---|
| 229 | _INFOLOG( QString( "Using locale: %1/%2" ).arg( sTranslationPath ).arg( sTranslationFile ) ); |
|---|
| 230 | } |
|---|
| 231 | else { |
|---|
| 232 | sTranslationPath = H2Core::DataPath::get_data_path() + "/i18n"; |
|---|
| 233 | total = sTranslationPath + "/" + sTranslationFile + ".qm"; |
|---|
| 234 | bTransOk = tor.load( total, "." ); |
|---|
| 235 | if (bTransOk) { |
|---|
| 236 | _INFOLOG( "Using locale: " + sTranslationPath + "/" + sTranslationFile ); |
|---|
| 237 | } |
|---|
| 238 | else { |
|---|
| 239 | _INFOLOG( "Warning: no locale found: " + sTranslationPath + "/" + sTranslationFile ); |
|---|
| 240 | } |
|---|
| 241 | } |
|---|
| 242 | if (tor.isEmpty()) { |
|---|
| 243 | _INFOLOG( "Warning: error loading locale: " + total ); |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | pQApp->installTranslator( &tor ); |
|---|
| 247 | |
|---|
| 248 | QString sStyle = pPref->getQTStyle(); |
|---|
| 249 | if (sStyle != "" ) { |
|---|
| 250 | pQApp->setStyle( sStyle ); |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | setPalette( pQApp ); |
|---|
| 254 | |
|---|
| 255 | SplashScreen *pSplash = new SplashScreen(); |
|---|
| 256 | |
|---|
| 257 | if (bNoSplash) { |
|---|
| 258 | pSplash->hide(); |
|---|
| 259 | } |
|---|
| 260 | else { |
|---|
| 261 | pSplash->show(); |
|---|
| 262 | } |
|---|
| 263 | |
|---|
| 264 | #ifdef LASH_SUPPORT |
|---|
| 265 | if ( H2Core::Preferences::getInstance()->useLash() ){ |
|---|
| 266 | if (lashClient->isConnected()) |
|---|
| 267 | { |
|---|
| 268 | lash_event_t* lash_event = lashClient->getNextEvent(); |
|---|
| 269 | if (lash_event && lash_event_get_type(lash_event) == LASH_Restore_File) |
|---|
| 270 | { |
|---|
| 271 | // notify client that this project was not a new one |
|---|
| 272 | lashClient->setNewProject(false); |
|---|
| 273 | |
|---|
| 274 | songFilename = ""; |
|---|
| 275 | songFilename.append(lash_event_get_string(lash_event)); |
|---|
| 276 | songFilename.append("/hydrogen.h2song"); |
|---|
| 277 | |
|---|
| 278 | // Logger::getInstance()->log("[LASH] Restore file: " + songFilename); |
|---|
| 279 | |
|---|
| 280 | lash_event_destroy(lash_event); |
|---|
| 281 | } |
|---|
| 282 | else if (lash_event) |
|---|
| 283 | { |
|---|
| 284 | // Logger::getInstance()->log("[LASH] ERROR: Instead of restore file got event: " + lash_event_get_type(lash_event)); |
|---|
| 285 | lash_event_destroy(lash_event); |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | } |
|---|
| 289 | #endif |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | MainForm *pMainForm = new MainForm( pQApp, songFilename ); |
|---|
| 293 | pMainForm->show(); |
|---|
| 294 | pSplash->finish( pMainForm ); |
|---|
| 295 | |
|---|
| 296 | pQApp->exec(); |
|---|
| 297 | |
|---|
| 298 | delete pSplash; |
|---|
| 299 | delete pMainForm; |
|---|
| 300 | delete pQApp; |
|---|
| 301 | delete pPref; |
|---|
| 302 | delete H2Core::EventQueue::get_instance(); |
|---|
| 303 | delete H2Core::AudioEngine::get_instance(); |
|---|
| 304 | |
|---|
| 305 | delete MidiMap::getInstance(); |
|---|
| 306 | delete ActionManager::getInstance(); |
|---|
| 307 | |
|---|
| 308 | _INFOLOG( "Quitting..." ); |
|---|
| 309 | cout << "\nBye..." << endl; |
|---|
| 310 | delete Logger::get_instance(); |
|---|
| 311 | |
|---|
| 312 | int nObj = Object::get_objects_number(); |
|---|
| 313 | if (nObj != 0) { |
|---|
| 314 | std::cerr << "\n\n\n " << to_string( nObj ).toStdString() << " alive objects\n\n" << std::endl << std::endl; |
|---|
| 315 | Object::print_object_map(); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | // pQApp->dumpObjectTree(); |
|---|
| 319 | |
|---|
| 320 | } |
|---|
| 321 | catch ( const H2Core::H2Exception& ex ) { |
|---|
| 322 | std::cerr << "[main] Exception: " << ex.what() << std::endl; |
|---|
| 323 | } |
|---|
| 324 | catch (...) { |
|---|
| 325 | std::cerr << "[main] Unknown exception X-(" << std::endl; |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | return 0; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | /** |
|---|
| 334 | * Show some information |
|---|
| 335 | */ |
|---|
| 336 | void showInfo() |
|---|
| 337 | { |
|---|
| 338 | cout << "\nHydrogen " + VERSION + " [" + __DATE__ + "] [http://www.hydrogen-music.org]" << endl; |
|---|
| 339 | cout << "Copyright 2002-2008 Alessandro Cominu" << endl; |
|---|
| 340 | // _INFOLOG( "Compiled modules: " + QString(COMPILED_FEATURES) << endl; |
|---|
| 341 | |
|---|
| 342 | if ( Object::is_using_verbose_log() ) { |
|---|
| 343 | cout << "\nVerbose log mode = active" << endl; |
|---|
| 344 | } |
|---|
| 345 | |
|---|
| 346 | cout << "\nHydrogen comes with ABSOLUTELY NO WARRANTY" << endl; |
|---|
| 347 | cout << "This is free software, and you are welcome to redistribute it" << endl; |
|---|
| 348 | cout << "under certain conditions. See the file COPYING for details\n" << endl; |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| 353 | /** |
|---|
| 354 | * Show the correct usage |
|---|
| 355 | */ |
|---|
| 356 | void showUsage() |
|---|
| 357 | { |
|---|
| 358 | std::cout << "Usage: hydrogen [-v] [-h] -s file" << std::endl; |
|---|
| 359 | std::cout << " -d, --driver AUDIODRIVER - Use the selected audio driver (jack, alsa, oss)" << std::endl; |
|---|
| 360 | std::cout << " -s, --song FILE - Load a song (*.h2song) at startup" << std::endl; |
|---|
| 361 | std::cout << " -n, --nosplash - Hide splash screen" << std::endl; |
|---|
| 362 | std::cout << " -V, --verbose - Print a lot of debugging info" << std::endl; |
|---|
| 363 | std::cout << " -v, --version - Show version info" << std::endl; |
|---|
| 364 | std::cout << " -h, --help - Show this help message" << std::endl; |
|---|
| 365 | } |
|---|