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
|
//=========================================================
// MusE
// Linux Music Editor
// $Id: ctrlpanel.cpp,v 1.1.1.1 2003/10/29 10:05:21 wschweer Exp $
// (C) Copyright 1999 Werner Schweer (ws@seh.de)
//=========================================================
#include <stdio.h>
#include <list>
#include "ctrlpanel.h"
#include "ctrlcanvas.h"
#include <qlayout.h>
#include <qpushbutton.h>
#include <qpopupmenu.h>
#include <qlabel.h>
#include <qtooltip.h>
#include <qsizepolicy.h>
#include "globals.h"
#include "midictrl.h"
#include "xml.h"
#include "icons.h"
#include "event.h"
#include "midieditor.h"
#include "part.h"
//---------------------------------------------------------
// CtrlPanel
//---------------------------------------------------------
CtrlPanel::CtrlPanel(QWidget* parent, MidiEditor* e, const char* name)
: QWidget(parent, name)
{
editor = e;
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
QGridLayout* cgrid = new QGridLayout(this, 4, 1, 0);
selCtrl = new QPushButton(tr("Sel"), this, "selCtrl");
selCtrl->setFont(font3);
selCtrl->setSizePolicy(
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
QToolTip::add(selCtrl, tr("select controller"));
pop = new QPopupMenu(selCtrl);
// destroy button
QPushButton* destroy = new QPushButton(tr("x"), this, "destroy");
destroy->setFont(font3);
destroy->setSizePolicy(
QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
QToolTip::add(destroy, tr("remove panel"));
// Cursor Position
connect(selCtrl, SIGNAL(clicked()), SLOT(ctrlPopup()));
connect(destroy, SIGNAL(clicked()), SIGNAL(destroyPanel()));
cgrid->addWidget(selCtrl, 0, 0);
cgrid->addWidget(destroy, 2, 0);
cgrid->setRowStretch(1, 50);
}
//---------------------------------------------------------
// setHeight
//---------------------------------------------------------
void CtrlPanel::setHeight(int h)
{
setFixedHeight(h);
}
struct TCtrl {
MidiController* ctrl;
bool exists;
TCtrl(MidiController* mc, bool flag) {
ctrl = mc;
exists = flag;
}
};
//---------------------------------------------------------
// ctrlPopup
//---------------------------------------------------------
void CtrlPanel::ctrlPopup()
{
//---------------------------------------------------
// build list of defined midi controllers
// check if controller exists in current parts
//---------------------------------------------------
std::list<struct TCtrl> clist;
for (iMidiController i = midiControllerList.begin();
i != midiControllerList.end(); ++i) {
clist.push_back(TCtrl(*i, false));
}
PartList* parts = editor->parts();
for (iPart ip = parts->begin(); ip != parts->end(); ++ip) {
EventList* el = ip->second->events();
for (iEvent ie = el->begin(); ie != el->end(); ++ie) {
MidiEvent* ev = (MidiEvent*)(ie->second);
if (ev->type() == MidiEvent::Ctrl7
|| ev->type() == MidiEvent::Ctrl14) {
for (std::list<struct TCtrl>::iterator i = clist.begin();
i != clist.end(); ++i) {
MidiController* ctrl = i->ctrl;
if (ev->cntrl() != ctrl->hnum())
continue;
// TODO: check more
i->exists = true;
break;
}
}
}
}
pop->clear();
pop->insertItem(tr("Velocity"), 1);
pop->insertItem(tr("Pitch"), 2);
for (std::list<struct TCtrl>::const_iterator i = clist.begin();
i != clist.end(); ++i) {
pop->insertItem(i->exists ? *dotIcon : QPixmap(),
i->ctrl->name());
}
pop->insertItem(QIconSet(*configureIcon), tr("other ..."), 3);
int rv = pop->exec(selCtrl->mapToGlobal(QPoint(0,0)));
if (rv == -1)
return;
QString s = pop->text(rv);
if (rv == 1) {
MidiController ctrl(MidiController::Velo, QString("Velocity"));
ctrl.setMinVal(0);
ctrl.setMaxVal(127);
emit controllerChanged(ctrl);
}
else if (rv == 2) {
MidiController ctrl(MidiController::Pitch, QString("Pitch"));
ctrl.setMinVal(-8192);
ctrl.setMaxVal(+8191);
emit controllerChanged(ctrl);
}
else if (rv == 3) {
configMidiController();
}
else {
for (iMidiController i = midiControllerList.begin();
i != midiControllerList.end(); ++i) {
if (s == (*i)->name()) {
emit controllerChanged(**i);
break;
}
}
}
}
|