~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to ctrl/ctrlpanel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//    $Id: ctrlpanel.cpp,v 1.2 2002/02/08 09:56:29 muse Exp $
 
5
//  (C) Copyright 1999 Werner Schweer (ws@seh.de)
 
6
//=========================================================
 
7
 
 
8
#include <stdio.h>
 
9
#include <list>
 
10
 
 
11
#include "ctrlpanel.h"
 
12
#include "ctrlcanvas.h"
 
13
 
 
14
#include <qlayout.h>
 
15
#include <qpushbutton.h>
 
16
#include <qpopupmenu.h>
 
17
#include <qlabel.h>
 
18
#include <qtooltip.h>
 
19
#include <qsizepolicy.h>
 
20
 
 
21
#include "globals.h"
 
22
#include "midictrl.h"
 
23
#include "xml.h"
 
24
#include "icons.h"
 
25
#include "event.h"
 
26
#include "midieditor.h"
 
27
#include "part.h"
 
28
 
 
29
//---------------------------------------------------------
 
30
//   CtrlPanel
 
31
//---------------------------------------------------------
 
32
 
 
33
CtrlPanel::CtrlPanel(QWidget* parent, MidiEditor* e, const char* name = 0)
 
34
   : QWidget(parent, name)
 
35
      {
 
36
      editor = e;
 
37
      setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
 
38
      QGridLayout* cgrid = new QGridLayout(this, 4, 1, 0);
 
39
 
 
40
      selCtrl = new QPushButton("Sel", this, "selCtrl");
 
41
      selCtrl->setFont(font3);
 
42
      selCtrl->setSizePolicy(
 
43
         QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
 
44
      QToolTip::add(selCtrl, tr("select controller"));
 
45
 
 
46
      pop = new QPopupMenu(selCtrl);
 
47
 
 
48
      // destroy button
 
49
      QPushButton* destroy = new QPushButton("x", this, "destroy");
 
50
      destroy->setFont(font3);
 
51
      destroy->setSizePolicy(
 
52
         QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
 
53
      QToolTip::add(destroy, tr("remove panel"));
 
54
 
 
55
      // Cursor Position
 
56
      connect(selCtrl, SIGNAL(clicked()), SLOT(ctrlPopup()));
 
57
      connect(destroy, SIGNAL(clicked()), SIGNAL(destroyPanel()));
 
58
 
 
59
      cgrid->addWidget(selCtrl, 0, 0);
 
60
      cgrid->addWidget(destroy,  2, 0);
 
61
      cgrid->setRowStretch(1,   50);
 
62
      }
 
63
 
 
64
//---------------------------------------------------------
 
65
//   setHeight
 
66
//---------------------------------------------------------
 
67
 
 
68
void CtrlPanel::setHeight(int h)
 
69
      {
 
70
      setFixedHeight(h);
 
71
      }
 
72
 
 
73
struct TCtrl {
 
74
      MidiController* ctrl;
 
75
      bool exists;
 
76
      TCtrl(MidiController* mc, bool flag) {
 
77
            ctrl = mc;
 
78
            exists = flag;
 
79
            }
 
80
      };
 
81
 
 
82
//---------------------------------------------------------
 
83
//   ctrlPopup
 
84
//---------------------------------------------------------
 
85
 
 
86
void CtrlPanel::ctrlPopup()
 
87
      {
 
88
      //---------------------------------------------------
 
89
      // build list of defined midi controllers
 
90
      //    check if controller exists in current parts
 
91
      //---------------------------------------------------
 
92
 
 
93
      std::list<struct TCtrl> clist;
 
94
 
 
95
      for (iMidiController i = midiControllerList.begin();
 
96
         i != midiControllerList.end(); ++i) {
 
97
            clist.push_back(TCtrl(*i, false));
 
98
            }
 
99
      PartList* parts = editor->parts();
 
100
      for (iPart ip = parts->begin(); ip != parts->end(); ++ip) {
 
101
            EventList* el = ip->second->events();
 
102
            for (iEvent ie = el->begin(); ie != el->end(); ++ie) {
 
103
                  MidiEvent* ev = (MidiEvent*)(ie->second);
 
104
                  if (ev->type() == MidiEvent::Ctrl7
 
105
                     || ev->type() == MidiEvent::Ctrl14) {
 
106
                        for (std::list<struct TCtrl>::iterator i = clist.begin();
 
107
                           i != clist.end(); ++i) {
 
108
                              MidiController* ctrl = i->ctrl;
 
109
                              if (ev->cntrl() != ctrl->hnum())
 
110
                                    continue;
 
111
                              // TODO: check more
 
112
                              i->exists = true;
 
113
                              break;
 
114
                              }
 
115
                        }
 
116
                  }
 
117
            }
 
118
 
 
119
      pop->clear();
 
120
      pop->insertItem("Velocity", 1);
 
121
      pop->insertItem("Pitch", 2);
 
122
 
 
123
      for (std::list<struct TCtrl>::const_iterator i = clist.begin();
 
124
         i != clist.end(); ++i) {
 
125
            pop->insertItem(i->exists ? *dotIcon : QPixmap(),
 
126
               i->ctrl->name());
 
127
            }
 
128
 
 
129
      pop->insertItem(QIconSet(*configureIcon), tr("other ..."), 3);
 
130
      int rv = pop->exec(selCtrl->mapToGlobal(QPoint(0,0)));
 
131
      if (rv == -1)
 
132
            return;
 
133
 
 
134
      QString s = pop->text(rv);
 
135
      if (rv == 1) {
 
136
            MidiController ctrl(MidiController::Velo, "Velocity");
 
137
            ctrl.setMinVal(0);
 
138
            ctrl.setMaxVal(127);
 
139
            emit controllerChanged(ctrl);
 
140
            }
 
141
      else if (rv == 2) {
 
142
            MidiController ctrl(MidiController::Pitch, "Pitch");
 
143
            ctrl.setMinVal(-8192);
 
144
            ctrl.setMaxVal(+8191);
 
145
            emit controllerChanged(ctrl);
 
146
            }
 
147
      else if (rv == 3) {
 
148
            configMidiController();
 
149
            }
 
150
      else {
 
151
            for (iMidiController i = midiControllerList.begin();
 
152
               i != midiControllerList.end(); ++i) {
 
153
                  if (s == (*i)->name()) {
 
154
                        emit controllerChanged(**i);
 
155
                        break;
 
156
                        }
 
157
                  }
 
158
            }
 
159
      }
 
160