-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodewindow.cpp
156 lines (122 loc) · 4.15 KB
/
nodewindow.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
#include "nodewindow.h"
#include "ui_nodewindow.h"
#include "vstnode.h"
#include "vsteditorwidget.h"
namespace En
{
NodeWindow::NodeWindow(En::VstNode* vstNode, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::NodeWindow),
m_vstNode(vstNode),
m_note(60)
{
ui->setupUi(this);
setWindowTitle(m_vstNode->displayLabel());
QVBoxLayout* layout = new QVBoxLayout(ui->vstPlaceholder);
En::VstEditorWidget* interface = new En::VstEditorWidget(vstNode, ui->vstPlaceholder);
layout->addWidget(interface);
m_vstEditorWidget = interface;
m_funkyTownPos = 0;
m_funkyTown << 0 << 0 << -2 << 0 << -5 << -5 << 0 << 5 << 4 << 0;
}
NodeWindow::~NodeWindow()
{
delete ui;
}
static void sendNote(En::VstNode* vstNode, unsigned char noteValue, unsigned char velocity) {
VstMidiEvent event = {kVstMidiType, sizeof(VstMidiEvent), 0, kVstMidiEventIsRealtime, 0, 0, {static_cast<char>(0x90), static_cast<char>(noteValue), static_cast<char>(velocity), 0}, 0, 0, 0, 0};
VstMidiEvent* pEvent = new VstMidiEvent(event);
vstNode->queueEvent(reinterpret_cast<VstEvent*>(pEvent));
}
void NodeWindow::on_testNoteButton_pressed()
{
int note = 0;
// FUNKYTOWN
if (QApplication::keyboardModifiers() == Qt::ShiftModifier) {
note = m_funkyTown[m_funkyTownPos] + 72;
m_funkyTownPos = (m_funkyTownPos + 1) % m_funkyTown.size();
} else {
note = m_note++;
if (m_note > 72) {
m_note = 60;
}
}
sendNote(m_vstNode, note, 100);
m_lastNote = note;
}
void NodeWindow::on_testNoteButton_released()
{
sendNote(m_vstNode, m_lastNote, 0);
}
static int keyEventToNote(QKeyEvent* event) {
// don't process if modifiers are used!
if (event->modifiers()) {
return -1;
}
int note = -1;
switch (event->key()) {
case Qt::Key_Z: note = 0; break;
case Qt::Key_S: note = 1; break;
case Qt::Key_X: note = 2; break;
case Qt::Key_D: note = 3; break;
case Qt::Key_C: note = 4; break;
case Qt::Key_V: note = 5; break;
case Qt::Key_G: note = 6; break;
case Qt::Key_B: note = 7; break;
case Qt::Key_H: note = 8; break;
case Qt::Key_N: note = 9; break;
case Qt::Key_J: note = 10; break;
case Qt::Key_M: note = 11; break;
case Qt::Key_Comma: note = 12; break;
case Qt::Key_L: note = 13; break;
case Qt::Key_Period: note = 14; break;
case Qt::Key_Q: note = 12; break;
case Qt::Key_2: note = 13; break;
case Qt::Key_W: note = 14; break;
case Qt::Key_3: note = 15; break;
case Qt::Key_E: note = 16; break;
case Qt::Key_R: note = 17; break;
case Qt::Key_5: note = 18; break;
case Qt::Key_T: note = 19; break;
case Qt::Key_6: note = 20; break;
case Qt::Key_Y: note = 21; break;
case Qt::Key_7: note = 22; break;
case Qt::Key_U: note = 23; break;
case Qt::Key_I: note = 24; break;
case Qt::Key_9: note = 25; break;
case Qt::Key_O: note = 26; break;
case Qt::Key_0: note = 27; break;
case Qt::Key_P: note = 28; break;
default: return -1;
}
int transpose = 48;
return note + transpose;
}
void NodeWindow::keyPressEvent(QKeyEvent* event) {
if (event->isAutoRepeat()) {
return;
}
int note = keyEventToNote(event);
if (note == -1) {
return QMainWindow::keyPressEvent(event);
}
sendNote(m_vstNode, note, 100);
}
void NodeWindow::keyReleaseEvent(QKeyEvent* event) {
int note = keyEventToNote(event);
if (note == -1) {
return QMainWindow::keyReleaseEvent(event);
}
sendNote(m_vstNode, note, 0);
}
void NodeWindow::on_showEditorButton_toggled(bool checked)
{
m_vstEditorWidget->setVisible(checked);
if (!checked) {
// this seems to be necessary to force the sizeHint to be updated so we actually shrink to fit
// if we're hiding...
QCoreApplication::processEvents();
adjustSize();
}
}
}