File: drumgridmain.cpp

package info (click to toggle)
libdrumstick 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,876 kB
  • sloc: cpp: 25,685; xml: 122; sh: 14; makefile: 5
file content (106 lines) | stat: -rw-r--r-- 4,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
    MIDI Sequencer C++ library
    Copyright (C) 2006-2024, Pedro Lopez-Cabanillas <plcl@users.sf.net>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QLibraryInfo>
#include <QMessageBox>
#include <QTranslator>
#include <drumstick/sequencererror.h>

#include "drumgrid.h"

const char* QSTR_APPNAME = "drumstick-drumgrid";
const char* QSTR_DOMAIN = "drumstick.sourceforge.net";
const char* PGM_DESCRIPTION = QT_TRANSLATE_NOOP("main", "Drumstick Drum Grid");
const char* errorstr = QT_TRANSLATE_NOOP("main", "Fatal error from the ALSA sequencer. "
    "This usually happens when the kernel doesn't have ALSA support, "
    "or the device node (/dev/snd/seq) doesn't exists, "
    "or the kernel module (snd_seq) is not loaded. "
    "Please check your ALSA/MIDI configuration.");

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QCoreApplication::setOrganizationName(QSTR_DOMAIN);
    QCoreApplication::setOrganizationDomain(QSTR_DOMAIN);
    QCoreApplication::setApplicationName(QSTR_APPNAME);
    QCoreApplication::setApplicationVersion(QStringLiteral(QT_STRINGIFY(VERSION)));
    QGuiApplication::setDesktopFileName("net.sourceforge.drumstick-drumgrid");

    QLocale locale;
    QTranslator qtTranslator;
    if ((locale.language() != QLocale::C) && (locale.language() != QLocale::English)) {
        if (qtTranslator.load( locale, "qt", "_",
            #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
                               QLibraryInfo::location(QLibraryInfo::TranslationsPath)
            #else
                               QLibraryInfo::path(QLibraryInfo::TranslationsPath)
            #endif
                              )) {
            QCoreApplication::installTranslator(&qtTranslator);
        } else {
            qWarning() << "Unable to load Qt translator:" << locale.name();
        }
    }

#if defined(Q_OS_WIN32)
    QString dataDir = QApplication::applicationDirPath() + "/";
#elif defined(Q_OS_MAC)
    QString dataDir = QApplication::applicationDirPath() + "/../Resources/";
#else
    QString dataDir = QApplication::applicationDirPath() + "/../share/drumstick/";
#endif

    QTranslator appTranslator;
    if ((locale.language() != QLocale::C) && (locale.language() != QLocale::English)) {
        if (appTranslator.load(locale, "drumstick-drumgrid", "_", dataDir)) {
            QCoreApplication::installTranslator(&appTranslator);
        } else {
            qWarning() << "Unable to load app translator:" << locale.name();
        }
    }

    QCommandLineParser parser;
    parser.setApplicationDescription(PGM_DESCRIPTION);
    auto helpOption = parser.addHelpOption();
    auto versionOption = parser.addVersionOption();
    QCommandLineOption portOption({"p", "port"}, QCoreApplication::translate("main", "MIDI Out Port."), "client:port");
    parser.addOption(portOption);
    parser.process(app);

    using drumstick::ALSA::SequencerError;

    try {
        DrumGrid w;
        if (parser.isSet(portOption)) {
            QString port = parser.value(portOption);
            w.subscribe(port);
        }
        w.show();
        return app.exec();
    } catch (const SequencerError& ex) {
        QMessageBox::critical(nullptr, QCoreApplication::translate("main", "Error"),
            QCoreApplication::translate("main", errorstr) + "\n" +
            QCoreApplication::translate("main", "Returned error was: ") + ex.qstrError() );
    } catch (...) {
        qWarning() << QCoreApplication::translate("main", errorstr); 
    }
    return EXIT_FAILURE;
}