1
//=========================================================
4
// $Id: dlist.cpp,v 1.4 2003/11/19 21:28:40 lunar_shuttle Exp $
5
// (C) Copyright 1999 Werner Schweer (ws@seh.de)
6
//=========================================================
15
#include "scrollscale.h"
16
#include <qpopupmenu.h>
17
#include <qlineedit.h>
19
#include "pitchedit.h"
23
enum DCols { COL_MUTE=0, COL_NAME, COL_QNT, COL_ENOTE, COL_LEN,
24
COL_ANOTE, COL_CHANNEL, COL_PORT,
25
COL_LV1, COL_LV2, COL_LV3, COL_LV4, COL_NONE=-1};
27
//---------------------------------------------------------
29
//---------------------------------------------------------
31
void DList::draw(QPainter& p, const QRect& rect)
36
int h = rect.height();
38
//---------------------------------------------------
40
//---------------------------------------------------
45
for (int i = 0; i < DRUM_MAPSIZE; ++i) {
51
DrumMap* dm = &drumMap[i];
53
p.fillRect(x, yy, w, TH, yellow);
55
p.eraseRect(x, yy, w, TH);
56
for (int k = 0; k < header->count(); ++k) {
57
int x = header->sectionPos(k);
58
int w = header->sectionSize(k);
59
QRect r = p.xForm(QRect(x+2, yy, w-4, TH));
61
int align = AlignVCenter | AlignHCenter;
64
p.setWorldXForm(false);
73
s = pitch2string(dm->anote);
76
s = pitch2string(dm->enote);
93
const QPixmap& pm = *muteIcon;
95
r.x() + r.width()/2 - pm.width()/2,
96
r.y() + r.height()/2 - pm.height()/2,
103
align = AlignVCenter | AlignLeft;
106
s.setNum(dm->channel+1);
109
s = midiPorts[dm->port].portname();
110
align = AlignVCenter | AlignLeft;
114
p.drawText(r, align, s);
119
//---------------------------------------------------
121
//---------------------------------------------------
124
int yy = (y / TH) * TH;
125
for (; yy < y + h; yy += TH) {
126
p.drawLine(x, yy, x + w, yy);
130
int y = (startY/TH) * TH;
134
p.drawLine(x, yy, x + w, yy);
135
p.drawLine(x, yy+TH, x + w, yy+TH);
139
//---------------------------------------------------
141
//---------------------------------------------------
143
p.setWorldXForm(false);
144
int n = header->count();
145
for (int i = 1; i < n; i++) {
146
int x = header->sectionPos(i);
147
p.drawLine(x, 0, x, height());
149
p.setWorldXForm(true);
152
//---------------------------------------------------------
154
//---------------------------------------------------------
156
void DList::devicesPopupMenu(DrumMap* t, int x, int y, bool changeAll)
158
QPopupMenu* p = midiPortsPopup(this);
159
int n = p->exec(mapToGlobal(QPoint(x, y)), 0);
164
for (int i=0; i<DRUM_MAPSIZE; i++)
170
//---------------------------------------------------------
171
// viewMousePressEvent
172
//---------------------------------------------------------
174
void DList::viewMousePressEvent(QMouseEvent* ev)
179
int button = ev->button();
180
bool shift = ev->state() & ShiftButton;
181
unsigned pitch = y / TH;
182
DrumMap* dm = &drumMap[pitch];
183
if (currentlySelected != 0) {
184
if (dm != currentlySelected) {
185
currentlySelected->selected = false;
187
currentlySelected = dm;
188
emit selectionChanged(currentlySelected);
189
emit keyFilterChanged(instr);
190
song->update(SC_DRUMMAP);
195
currentlySelected = dm;
197
emit selectionChanged(currentlySelected);
198
emit keyFilterChanged(instr);
199
song->update(SC_DRUMMAP);
207
DCols col = DCols(x2col(x));
211
if (button == QMouseEvent::RightButton)
213
else if (button == QMouseEvent::MidButton)
216
// Check if we're already editing anything and have pressed the mouse elsewhere
217
// In that case, treat it as if a return was pressed
218
if (button == QMouseEvent::LeftButton) {
219
if ((editEntry && editEntry != dm || col != selectedColumn) && editEntry != 0) {
228
if (button == QMouseEvent::LeftButton)
229
dm->mute = !dm->mute;
232
if (button == QMouseEvent::RightButton) {
233
bool changeAll = ev->state() & ControlButton;
234
devicesPopupMenu(dm, mapx(x), mapy(pitch * TH), changeAll);
242
val = dm->enote + incVal;
247
// Check if there is any other drumMap with the same inmap value
248
// If so, switch the inmap between the instruments
249
for (int i=0; i<DRUM_MAPSIZE; i++) {
250
if (drumMap[i].enote == val && &drumMap[i] != dm) {
251
drumInmap[dm->enote] = i;
252
drumMap[i].enote = dm->enote;
257
drumInmap[val] = pitch; // The inmap for the particular note now points to the instrument we're currently at
260
val = dm->len + incVal;
266
val = dm->anote + incVal;
272
emit keyPressed(dm->enote, shift); //Send input-key
275
val = dm->channel + incVal;
280
if (ev->state() & ControlButton) {
281
for (int i=0; i<DRUM_MAPSIZE; i++)
282
drumMap[i].channel = val;
288
val = dm->lv1 + incVal;
296
val = dm->lv2 + incVal;
304
val = dm->lv3 + incVal;
312
val = dm->lv4 + incVal;
320
emit keyPressed(dm->enote, shift); //Send input key
325
int channel = t->channel();
326
if (button == QMouseEvent::RightButton) {
330
else if (button == QMouseEvent::MidButton) {
334
if (channel != t->channel()) {
335
t->setChannel(channel);
336
emit channelChanged();
346
//---------------------------------------------------------
347
// viewMouseDoubleClickEvent
348
//---------------------------------------------------------
350
void DList::viewMouseDoubleClickEvent(QMouseEvent* ev)
354
unsigned pitch = y / TH;
355
DrumMap* dm = &drumMap[pitch];
357
int section = header->sectionAt(x);
359
if (section == COL_NAME || section == COL_LEN || section == COL_LV1 ||
360
section == COL_LV2 || section == COL_LV3 || section == COL_LV4) {
363
editor = new QLineEdit(this);
364
connect(editor, SIGNAL(returnPressed()),
365
SLOT(returnPressed()));
366
editor->setFrame(true);
368
int colx = mapx(header->sectionPos(section));
369
int colw = rmapx(header->sectionSize(section));
370
int coly = mapy(pitch * TH);
371
int colh = rmapy(TH);
372
selectedColumn = section; //Store selected column to have an idea of which one was selected when return is pressed
375
editor->setText(dm->name);
379
editor->setText(QString::number(dm->len));
384
editor->setText(QString::number(dm->lv1));
388
editor->setText(QString::number(dm->lv2));
392
editor->setText(QString::number(dm->lv3));
396
editor->setText(QString::number(dm->lv4));
401
editor->setGeometry(colx, coly, colw, colh);
402
//In all cases but the column name, select all text:
403
if (section != COL_NAME)
408
viewMousePressEvent(ev);
411
//---------------------------------------------------------
413
//---------------------------------------------------------
415
int DList::x2col(int x) const
419
for (; col < header->count(); col++) {
420
w += header->cellSize(col);
424
if (col == header->count())
426
return header->mapToLogical(col);
429
//---------------------------------------------------------
431
//---------------------------------------------------------
433
void DList::moveSelection(int)
437
//---------------------------------------------------------
439
//---------------------------------------------------------
441
void DList::sizeChange(int, int, int)
446
//---------------------------------------------------------
448
//---------------------------------------------------------
450
void DList::returnPressed()
453
if (selectedColumn != COL_NAME) {
454
val = atoi(editor->text().ascii());
455
if (selectedColumn != COL_LEN) {
456
if (val > 127) //Check bounds for lv1-lv4 values
463
switch(selectedColumn) {
465
editEntry->name = editor->text();
469
editEntry->len = atoi(editor->text().ascii());
473
editEntry->lv1 = val;
477
editEntry->lv2 = val;
481
editEntry->lv3 = val;
485
editEntry->lv4 = val;
489
printf("Return pressed in unknown column\n");
499
//---------------------------------------------------------
501
//---------------------------------------------------------
503
void DList::moved(int, int)
508
//---------------------------------------------------------
510
//---------------------------------------------------------
512
void DList::tracklistChanged()
516
//---------------------------------------------------------
518
//---------------------------------------------------------
520
void DList::songChanged(int flags)
522
if (flags & SC_DRUMMAP)
527
//---------------------------------------------------------
529
//---------------------------------------------------------
531
DList::DList(QHeader* h, QWidget* parent, int ymag)
532
: View(parent, 1, ymag)
537
header->setTracking(true);
538
connect(header, SIGNAL(sizeChange(int,int,int)),
539
SLOT(sizeChange(int,int,int)));
540
connect(header, SIGNAL(moved(int,int)), SLOT(moved(int,int)));
541
setFocusPolicy(QWidget::StrongFocus);
545
currentlySelected = 0;
548
//---------------------------------------------------------
550
//---------------------------------------------------------
553
if (currentlySelected != 0)
554
currentlySelected->selected = false; //Reset the global
557
//---------------------------------------------------------
558
// viewMouseMoveEvent
559
//---------------------------------------------------------
561
void DList::viewMouseMoveEvent(QMouseEvent* ev)
564
int delta = curY - startY;
572
setCursor(QCursor(sizeVerCursor));
583
//---------------------------------------------------------
584
// viewMouseReleaseEvent
585
//---------------------------------------------------------
587
void DList::viewMouseReleaseEvent(QMouseEvent* ev)
591
unsigned dPitch = y / TH;
592
DrumMap dm = drumMap[sPitch];
593
drumMap[sPitch] = drumMap[dPitch];
594
drumMap[dPitch] = dm;
595
setCursor(QCursor(arrowCursor));
597
drumInmap[drumMap[sPitch].enote] = sPitch;
598
drumOutmap[drumMap[sPitch].anote] = sPitch;
599
drumInmap[drumMap[dPitch].enote] = dPitch;
600
drumOutmap[drumMap[dPitch].anote] = dPitch;
601
currentlySelected = &drumMap[dPitch];
602
emit mapChanged(sPitch, dPitch); //Pitch change throughout the whole track done in canvas
610
bool shift = ev->state() & ShiftButton;
611
unsigned pitch = y / TH;
612
DrumMap* dm = &drumMap[pitch];
614
DCols col = DCols(x2col(x));
618
emit keyReleased(dm->enote, shift);
621
emit keyReleased(dm->enote, shift);
628
int DList::getSelectedInstrument()
630
if (currentlySelected == 0)
633
return drumInmap[currentlySelected->enote];