-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
188 lines (160 loc) · 6.54 KB
/
main.cpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/****************************************************************************
**
** Copyright (C) 2018 Robert Vetter.
**
** This file is part of the MagicstompFrenzy - an editor for Yamaha Magicstomp
** effect processor
**
** THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
** ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
** IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
** PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
**
** GNU General Public License Usage
** This file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version . The licenses are
** as published by the Free Software Foundation and appearing in the file LICENSE
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**/
#include "mainwindow.h"
#include <QCommandLineParser>
#include "midiportmodel.h"
int main(int argc, char *argv[])
{
MidiApplication a(argc, argv);
a.setApplicationName("MagicstompFrenzy");
a.setOrganizationName("RobertVetter");
a.setOrganizationDomain("www.robertvetter.com");
a.setApplicationVersion("1.00");
a.setWindowIcon(QIcon(":magicstomp.png"));
MainWindow mw( a.ReadablePortsModel(), a.WritablePortsModel());
QObject::connect( &a, SIGNAL(midiEventReceived(MidiEvent *)), &mw, SLOT(midiEvent(MidiEvent*)));
/* Example command line for auto start:
* --ignorepreferences --hideeditor --mwx 0 --mwy 0 --mwh 400 --mww 600 --smf /home/robert/MagicstompHoldsworthSounds.mid --findandconnectms 0 --connectmidiinport MS1x1
*/
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
//QCommandLineOption hideEditorWindowOption(QStringList() << "hideeditor", "No editor");
//parser.addOption(hideEditorWindowOption);
QCommandLineOption ignorePreferencesOption(QStringList() << "ignorepreferences", "No preferences");
parser.addOption(ignorePreferencesOption);
QCommandLineOption mwxOption(QStringList() << "mwx", "Main Window X", "0");
parser.addOption(mwxOption);
QCommandLineOption mwyOption(QStringList() << "mwy", "Main Window Y", "0");
parser.addOption(mwyOption);
QCommandLineOption mwwOption(QStringList() << "mww", "Main Window Width", "400");
parser.addOption(mwwOption);
QCommandLineOption mwhOption(QStringList() << "mwh", "Main Window Height", "400");
parser.addOption(mwhOption);
QCommandLineOption smfOption(QStringList() << "smf", "SMF with patches to import", "Filename");
parser.addOption(smfOption);
QCommandLineOption findandconnectMSOption(QStringList() << "findandconnectms", "index of the MS in the system", "index");
parser.addOption(findandconnectMSOption);
QCommandLineOption connectmidiInPortOption(QStringList() << "connectmidiinport", "Port Name", "name");
parser.addOption(connectmidiInPortOption);
parser.process(a);
if(! parser.isSet(ignorePreferencesOption))
{
mw.restoreSettings();
}
// if(parser.isSet(hideEditorWindowOption))
// {
// mw.hideEditor();
// }
if(parser.isSet(mwxOption) && parser.isSet(mwyOption))
{
QString xStr = parser.value(mwxOption);
QString yStr = parser.value(mwyOption);
bool okx;
bool oky;
int x = xStr.toInt( &okx);
int y = yStr.toInt( &oky);
if( okx && oky)
mw.move( x, y);
}
if(parser.isSet(mwwOption) && parser.isSet(mwhOption))
{
QString wStr = parser.value(mwhOption);
QString hStr = parser.value(mwwOption);
bool okw;
bool okh;
int w = wStr.toInt( &okw);
int h = hStr.toInt( &okh);
if( okw && okh)
mw.resize( w, h);
}
if(parser.isSet(smfOption))
{
bool res;
QString file = parser.value(smfOption);
res = mw.importSMF( file , MainWindow::PatchListType::User);
if ( ! res)
{
printf("Error opening file %s\n", file.toLocal8Bit().constData());
exit(1);
}
}
if(parser.isSet(findandconnectMSOption))
{
QString indexStr = parser.value(findandconnectMSOption);
bool ok;
int msindex = indexStr.toInt( &ok);
int mscounter = 0;
if(ok)
{
MidiPortModel *midiportmodel = a.ReadablePortsModel();
for(int r = 0; r<midiportmodel->rowCount(); r++)
{
QString name = midiportmodel->data( midiportmodel->index(r, 0), Qt::DisplayRole ).toString();
if(name.contains("UB99"))
{
if( mscounter == msindex)
{
MidiClientPortId id = qvariant_cast<MidiClientPortId> (midiportmodel->data( midiportmodel->index(r, 0), MidiPortModel::ClientPortIdRole));
a.changeReadableMidiPortStatus( id, true);
break;
}
mscounter++;
}
}
midiportmodel = a.WritablePortsModel();
mscounter = 0;
for(int r = 0; r<midiportmodel->rowCount(); r++)
{
QString name = midiportmodel->data( midiportmodel->index(r, 0), Qt::DisplayRole ).toString();
if(name.contains("UB99"))
{
if( mscounter == msindex)
{
MidiClientPortId id = qvariant_cast<MidiClientPortId> (midiportmodel->data( midiportmodel->index(r, 0), MidiPortModel::ClientPortIdRole));
a.changeWritebleMidiPortStatus( id, true);
break;
}
mscounter++;
}
}
}
}
if(parser.isSet(connectmidiInPortOption))
{
QString portname = parser.value(connectmidiInPortOption);
MidiPortModel *midiportmodel = a.ReadablePortsModel();
for(int r = 0; r<midiportmodel->rowCount(); r++)
{
QString name = midiportmodel->data( midiportmodel->index(r, 0), Qt::DisplayRole ).toString();
if(name.contains(portname))
{
MidiClientPortId id = qvariant_cast<MidiClientPortId> (midiportmodel->data( midiportmodel->index(r, 0), MidiPortModel::ClientPortIdRole));
a.changeReadableMidiPortStatus( id, true);
break;
}
}
}
mw.show();
return a.exec();
}