1 /*!
2  * @file seqwidget.h
3  * @brief Member definitions for the SeqWidget GUI class.
4  *
5  *
6  *      Copyright 2009 - 2017 <qmidiarp-devel@lists.sourceforge.net>
7  *
8  *      This program is free software; you can redistribute it and/or modify
9  *      it under the terms of the GNU General Public License as published by
10  *      the Free Software Foundation; either version 2 of the License, or
11  *      (at your option) any later version.
12  *
13  *      This program is distributed in the hope that it will be useful,
14  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *      GNU General Public License for more details.
17  *
18  *      You should have received a copy of the GNU General Public License
19  *      along with this program; if not, write to the Free Software
20  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  *      MA 02110-1301, USA.
22  */
23 
24 #ifndef SEQWIDGET_H
25 #define SEQWIDGET_H
26 
27 #include <QSignalMapper>
28 
29 #include "midiseq.h"
30 #include "inoutbox.h"
31 #include "slider.h"
32 #include "seqscreen.h"
33 #include "cursor.h"
34 
35 
36 /*!
37  * @brief GUI class associated with and controlling a MidiSeq worker
38 
39  * It controls the MidiSeq step sequencer, which is transferred as a pointer
40  * when SeqWidget is instantiated. It is embedded in a DockWidget on
41  * MainWindow level. It can read its parameter set from an XML stream
42  * by calling its readData() function. It instantiates a SeqScreen
43  * and interacts with it.
44  *
45 */
46 class SeqWidget : public InOutBox
47 {
48     Q_OBJECT
49 
50     MidiSeq *midiSeq;
51     bool lastMute;      /**< Contains the mute state of the last waveForm point modified by mouse click*/
52     bool recordMode;    /**< Is set to True if incoming notes are to be step-recorded*/
53 
54 /* PUBLIC MEMBERS */
55   public:
56 #ifdef APPBUILD
57 /*!
58  * @brief Constructor for SeqWidget. It creates the GUI and an SeqScreen
59  * instance.
60  *
61  * @param p_midiSeq Associated MidiSeq Object
62  * @param p_globStore The Application-wide globStore widget
63  * @param portCount Number of available MIDI output ports
64  * @param compactStyle If set to True, Widget will use reduced spacing and small fonts
65  * @param mutedAdd If set to True, the module will be added in muted state
66  * @param inOutVisible Add the module with visible InOutBox or not
67  * @param name The name of the module preceded by its type (Arp: , etc...)
68  */
69     SeqWidget(MidiSeq *p_midiSeq, GlobStore *p_globStore,
70             int portCount, bool compactStyle,
71             bool mutedAdd = false, bool inOutVisible = true,
72             const QString& name = "");
73 
74 #else
75     SeqWidget(
76             bool compactStyle,
77             bool mutedAdd = false, bool inOutVisible = true);
78 #endif
79 
80     QVector<Sample> data;
81     SeqScreen *screen;
82     Cursor *cursor;
83 
84     QComboBox *resBox, *sizeBox, *freqBox;
85     QComboBox *loopBox;
86     QCheckBox *dispVert[4];
87     Slider *velocity, *transpose, *notelength;
88     QAction *recordAction;
89     QSignalMapper *dispSignalMapper;
90     int dispVertIndex;
91     int resBoxIndex;
92     int sizeBoxIndex;
93 
94     QVector<Sample> getCustomWave();
95     QVector<bool> getMuteMask();
96 
97 
98 #ifdef APPBUILD
99 /*!
100 * @brief returns the MidiSeq instance associated with this GUI
101 * Widget.
102 * @return MidiSeq instance associated with this GUI
103 */
104     MidiSeq *getMidiWorker();
105 
106 /*!
107 * @brief reads all parameters of this module from an XML stream
108 * passed by the caller, i.e. MainWindow.
109 *
110 * @param xml QXmlStreamWriter to read from
111 */
112     void readData(QXmlStreamReader& xml);
113 /*!
114 * @brief writes all parameters of this module to an XML stream
115 * passed by the caller, i.e. MainWindow.
116 *
117 * @param xml QXmlStreamWriter to write to
118 */
119     void writeData(QXmlStreamWriter& xml);
120 /*!
121 * @brief copies all Seq module GUI parameters from
122 * fromWidget
123 *
124 * @param fromWidget pointer to the SeqWidget parameters are to be taken from
125 */
126     void copyParamsFrom(SeqWidget *fromWidget);
127 
128     void doStoreParams(int ix);
129     void doRestoreParams(int ix);
130     void updateDisplay();
131     void handleController(int ccnumber, int channel, int value);
updateCursorPos()132     void updateCursorPos() {cursor->updatePosition(getFramePtr()); }
133 #endif
134 
135 /* SIGNALS */
136   signals:
137 /*! @brief Currently not in use. */
138     void patternChanged();
139 /*! @brief Is re-emitted when a SeqScreen::mouseEvent() is received
140  * and no pointer to a MidiWorker is present (LV2 build). */
141     void mouseSig(double, double, int, int);
142 
143 /* PUBLIC SLOTS */
144   public slots:
145 /*!
146 * @brief Slot currently not in use.
147 * @param val Waveform index to choose as present in SeqWidget::loadWaveForms.
148 *
149 */
150     void updateWaveForm(int);
151 /*!
152 * @brief Slot for the SeqWidget::resBox combobox. Sets the resolution
153 * of the sequencer.
154 *
155 * It sets MidiSeq::res and updates the SeqScreen of this module.
156 * @param val Resolution index from SeqWidget::seqResValues to set.
157 *
158 */
159     void updateRes(int);
160 /*!
161 * @brief Slot for the SeqWidget::sizeBox combobox. Sets the waveform size
162 * of the sequencer.
163 *
164 * It sets MidiSeq::size and updates the SeqScreen of this module.
165 * @param val Size (number of bars) of the waveform.
166 *
167 */
168     void updateSize(int);
169 /*!
170 * @brief Slot for the SeqWidget::loopBox combobox. Sets the loop mode
171 * of the sequencer.
172 *
173 * It sets MidiSeq::reverse, MidiSeq::pingpong and MidiSeq::enableLoop
174 * @param val Combination index ranging from 0 to 5
175 *
176 */
177     void updateLoop(int);
178 /*!
179 * @brief Slot for the SeqWidget::velocity slider. Sets the note velocity
180 * of the sequencer.
181 *
182 * @param val New note velocity (0 ... 127).
183 *
184 */
185     void updateVelocity(int val);
186 /*!
187 * @brief Slot for the SeqWidget::transpose slider. Sets the global transpose
188 * of the sequencer in semitones (-24 ... 24).
189 *
190 * @param val New global transpose of the sequencer in semitones (-24 ... 24).
191 *
192 */
193     void updateNoteLength(int val);
194     void updateTranspose(int val);
195 
196     void setRecord(bool on);
197     void setDispVert(int mode);
198     void updateDispVert(int mode);
199 
200 /*!
201 * @brief Slot for the SeqScreen::mouseEvent signal.
202 *
203 * Mutes or sets a wave point when the mouse is pressed or
204 * released or moved with held buttons.
205 * The mouse events are generated by the SeqScreen.
206 * It calls MidiSeq::mouseEvent()
207 * or emits the mouseSig() signal if no pointer to a MIDI worker was
208 * transferred (LV2 build).
209 *
210 * @param mouseX Normalized mouse position on SeqScreen in X
211 * direction (0.0 ... 1.0)
212 * @param mouseY Normalized mouse position on SeqScreen in Y
213 * direction (0.0 ... 1.0)
214 * @param buttons 1 for left mouse button, 2 for right mouse button
215 * @param pressed 0 for mouse moved, 1 for mouse pressed, 2 for mouse released
216 *
217 */
218     void mouseEvent(double, double, int, int pressed);
219 
getLoopMarker()220     int getLoopMarker() { return midiSeq->loopMarker; }
getReverse()221     bool getReverse() { return midiSeq->reverse; }
sliderToTickLen(int val)222     int sliderToTickLen(int val) { return (val * TPQN / 64); }
tickLenToSlider(int val)223     int tickLenToSlider(int val) { return (val * 64 / TPQN); }
224 };
225 
226 #endif
227