-
Notifications
You must be signed in to change notification settings - Fork 4
/
mainwindow.h
174 lines (131 loc) · 4.81 KB
/
mainwindow.h
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
/****************************************************************************
**
** 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.
**/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QQueue>
#include <QSet>
#include <QMap>
class MidiPortModel;
class PatchListModel;
class QTableView;
class QPushButton;
class QVBoxLayout;
class ProgressWidget;
class QListView;
class MidiEvent;
class QItemSelection;
class QDoubleSpinBox;
class QLabel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( MidiPortModel *readableportsmodel, MidiPortModel *writableportsmodel, QWidget *parent = Q_NULLPTR);
enum PatchListType { User, GuitarPreset, BassPreset, AcousticPreset, SMFImport, NumPatchListTypes};
public slots:
void midiEvent(MidiEvent *event);
bool importSMF(const QString &fileName, PatchListType type);
bool importUB99(const QString &fileName, PatchListType type);
void hideEditor();
void restoreSettings();
protected:
void closeEvent(QCloseEvent *event) override;
private slots:
void requestAll();
void sendAll(bool startMidiOutTimer = true);
void requestPatch(int patchIndex);
void sendPatch(int patchIndex, bool sendToTmpArea = true, PatchListType type=User, bool startMidiOutTimer = true);
void parameterToBeChanged(int offset, int length, QWidget *editWidget);
void parameterChanged(int offset, int length, QWidget *editWidget);
void timeout();
void midiOutTimeOut();
void cancelTransmission();
void patchListDoubleClicked(const QModelIndex& idx);
void patchListSelectionChanged();
void putGuiToTransmissionState( bool isTransmitting, bool sending);
void swapButtonPressed();
void copyButtonPressed();
void undoRedoButtonPressed();
void showPreferences();
void saveSettings();
void setMIDIChannel(int val) { midiChannel = val; }
void onImport();
void onExport();
void onPatchTypeEditorChanged( int typeId);
void onParamToCCChaged( const QString &name, int newVal, int oldVal);
private:
bool hasValidUserPatches() const;
void loadPresetPatches(int index, const QString &filename);
PatchListType getCurrentPatchType() const;
void buildCCToWidgetMap();
MidiPortModel *readablePortsModel;
MidiPortModel *writablePortsModel;
//PatchListModel *patchListModel;
QList<PatchListModel *> patchListModelList;
PatchListModel *tmpPatchListModel;
QTimer *timeOutTimer;
QTimer *midiOutTimer;
QQueue< MidiEvent *> midiOutQueue;
//QList<QByteArray> patchDataList;
QList<QList<QByteArray>> newPatchDataList;
QList<QByteArray> tmpPatchDataList;
QList<QMap<int, QPair<QByteArray, bool>>> backupPatchesMapList;
QTabWidget *patchTabWidget;
QTableView *patchListView;
QPushButton *requestButton;
QPushButton *sendButton;
ProgressWidget *progressWidget;
QPushButton *swapButton;
QPushButton *copyButton;
QPushButton *undoRedoButton;
QVBoxLayout *patchListLayout;
QAction *showPreferencesAction;
QAction *importAction;
QAction *exportAction;
QLabel *patchNameLabel;
int midiChannel{0};
int currentPatchTransmitted;
QPair<PatchListType, int> currentPatchEdited;
enum CCMode { Continious, SwitchLatch };
enum CCInitMode { Miniumum, PatchValue };
struct widgetWithVal
{
QDoubleSpinBox *dspinBox;
double storedValue;
CCMode ccMode;
CCInitMode ccInitMode;
};
QMap<int, widgetWithVal> ccToWidgetMap;
QMap<QString, int> nameToCCMap;
// value (int) bytes usage:
// Lowest byte - CC Number
// Lowe nibble of second lowest byte - CC Mode
// High nibble of second lowest byte - CC Init Mode
QByteArray tmpArray; // used to store parameter data needed to be restored after programatical ( CC ) change of data
bool cancelOperation;
bool isInTransmissionState;
bool isInImportState;
static char calcChecksum(const char *data, int dataLength);
};
#endif // MAINWINDOW_H