~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to confmport.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: confmport.cpp,v 1.2 2002/02/28 09:02:25 muse Exp $
 
5
//
 
6
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
 
7
//=========================================================
 
8
 
 
9
#include <list>
 
10
#include <termios.h>
 
11
 
 
12
#include <qlistview.h>
 
13
#include <qlayout.h>
 
14
#include <qpushbutton.h>
 
15
#include <qlineedit.h>
 
16
#include <qcombobox.h>
 
17
#include <qlabel.h>
 
18
#include <qbuttongroup.h>
 
19
#include <stdio.h>
 
20
#include <qpopupmenu.h>
 
21
#include <qgroupbox.h>
 
22
#include <qradiobutton.h>
 
23
#include <qspinbox.h>
 
24
#include <qcheckbox.h>
 
25
#include <qsignalmapper.h>
 
26
#include <qtooltip.h>
 
27
#include <qfiledialog.h>
 
28
#include <qtoolbutton.h>
 
29
 
 
30
#include "confmport.h"
 
31
#include "app.h"
 
32
#include "icons.h"
 
33
#include "globals.h"
 
34
#include "transport.h"
 
35
#include "arranger.h"
 
36
#include "seq.h"
 
37
#include "device.h"
 
38
#include "midiport.h"
 
39
#include "driver/mididev.h"
 
40
#include "driver/midiserial.h"
 
41
#include "xml.h"
 
42
#include "midisyncimpl.h"
 
43
#include "midifilterimpl.h"
 
44
#include "ctrlcombo.h"
 
45
#include "minstrument.h"
 
46
#include "synth.h"
 
47
#include "midithread.h"
 
48
 
 
49
enum { DEVCOL_NO = 0, DEVCOL_GUI, DEVCOL_REC, DEVCOL_INSTR, DEVCOL_NAME,
 
50
       DEVCOL_STATE };
 
51
 
 
52
//---------------------------------------------------------
 
53
//   speed2int
 
54
//---------------------------------------------------------
 
55
 
 
56
static int speed2int(const QString& s)
 
57
      {
 
58
      if (s == "9600")
 
59
            return B9600;
 
60
      if (s == "19200")
 
61
            return B19200;
 
62
      if (s == "38400")
 
63
            return B38400;
 
64
      return 0;
 
65
      }
 
66
 
 
67
//---------------------------------------------------------
 
68
//   speed2idx
 
69
//---------------------------------------------------------
 
70
 
 
71
static int speed2idx(const QString& s)
 
72
      {
 
73
      if (s == "9600")
 
74
            return 0;
 
75
      if (s == "19200")
 
76
            return 1;
 
77
      if (s == "38400")
 
78
            return 2;
 
79
      return 0;
 
80
      }
 
81
 
 
82
//---------------------------------------------------------
 
83
//   speed2str
 
84
//---------------------------------------------------------
 
85
 
 
86
static QString speed2str(int s)
 
87
      {
 
88
      switch(s) {
 
89
            case B9600:   return "9600";
 
90
            case B19200:   return "19200";
 
91
            case B38400:   return "38400";
 
92
            }
 
93
      return "?";
 
94
      }
 
95
 
 
96
 
 
97
//---------------------------------------------------------
 
98
//   handshaking2int
 
99
//---------------------------------------------------------
 
100
 
 
101
static int handshaking2int(const QString& s)
 
102
      {
 
103
      if (s == "None")
 
104
            return 0;
 
105
      if (s == "RTS/CTS")
 
106
            return 1;
 
107
      if (s == "Xon/Xoff")
 
108
            return 2;
 
109
      return 0;
 
110
      }
 
111
 
 
112
//---------------------------------------------------------
 
113
//   handshaking2str
 
114
//---------------------------------------------------------
 
115
 
 
116
static QString handshaking2str(int v)
 
117
      {
 
118
      switch(v) {
 
119
            case 0:  return "None";
 
120
            case 1:  return "RTS/CTS";
 
121
            case 2:  return "Xon/Xoff";
 
122
            }
 
123
      return "?";
 
124
      }
 
125
 
 
126
//---------------------------------------------------------
 
127
//   type2int
 
128
//---------------------------------------------------------
 
129
 
 
130
static int type2int(const QString& s)
 
131
      {
 
132
      if (s == "Raw Device")
 
133
            return 0;
 
134
      if (s == "Serial Port")
 
135
            return 1;
 
136
      if (s == "Pipe")
 
137
            return 2;
 
138
      return 0;
 
139
      }
 
140
 
 
141
//---------------------------------------------------------
 
142
//   type2str
 
143
//---------------------------------------------------------
 
144
 
 
145
static QString type2str(int t)
 
146
      {
 
147
      switch(t) {
 
148
            case 0:  return "Raw Device";
 
149
            case 1:  return "Serial Port";
 
150
            case 2:  return "Pipe";
 
151
            }
 
152
      return "?";
 
153
      }
 
154
 
 
155
//---------------------------------------------------------
 
156
//   MidiRawDeviceDialog
 
157
//---------------------------------------------------------
 
158
 
 
159
MidiRawDeviceDialog::MidiRawDeviceDialog(QWidget* parent=0, const char* name = 0,
 
160
   bool modal = false, WFlags fl = 0)
 
161
   : MidiRawDeviceDialogBase(parent, name, modal, fl)
 
162
      {
 
163
      connect(buttonDeviceNew, SIGNAL(clicked()), SLOT(deviceNew()));
 
164
      connect(buttonDeviceDelete, SIGNAL(clicked()), SLOT(deviceDelete()));
 
165
      connect(buttonDevicePath, SIGNAL(clicked()), SLOT(devicePath()));
 
166
      connect(editName, SIGNAL(textChanged(const QString&)), SLOT(editNameChanged(const QString&)));
 
167
      connect(editPath, SIGNAL(textChanged(const QString&)), SLOT(editPathChanged(const QString&)));
 
168
      connect(virtPorts, SIGNAL(valueChanged(int)), SLOT(virtPortsChanged(int)));
 
169
      connect(speed, SIGNAL(activated(const QString&)), SLOT(speedChanged(const QString&)));
 
170
      connect(handshaking, SIGNAL(activated(const QString&)), SLOT(handshakingChanged(const QString&)));
 
171
      connect(type, SIGNAL(activated(const QString&)), SLOT(typeChanged(const QString&)));
 
172
      connect(listDevices, SIGNAL(selectionChanged(QListViewItem*)),
 
173
         SLOT(devicesSelectionChanged(QListViewItem*)));
 
174
      listDevices->setColumnAlignment(3, AlignHCenter);
 
175
      }
 
176
 
 
177
//---------------------------------------------------------
 
178
//   populate
 
179
//---------------------------------------------------------
 
180
 
 
181
void MidiRawDeviceDialog::populate()
 
182
      {
 
183
      QString vp;
 
184
 
 
185
      listDevices->clear();
 
186
      for (iSerialDevice i = serialDevices.begin(); i != serialDevices.end(); ++i) {
 
187
            vp.setNum((*i)->vports());
 
188
            new QListViewItem(listDevices,
 
189
               (*i)->name(),
 
190
               (*i)->path(),
 
191
               type2str((*i)->type()),
 
192
               vp,
 
193
               speed2str((*i)->speed()),
 
194
               handshaking2str((*i)->handshaking())
 
195
               );
 
196
            }
 
197
      listDevices->setCurrentItem(listDevices->firstChild());
 
198
      if (listDevices->childCount() == 0) {
 
199
            buttonDeviceDelete->setEnabled(false);
 
200
            editName->setEnabled(false);
 
201
            editPath->setEnabled(false);
 
202
            virtPorts->setEnabled(false);
 
203
            speed->setEnabled(false);
 
204
            handshaking->setEnabled(false);
 
205
            type->setEnabled(false);
 
206
            }
 
207
      }
 
208
 
 
209
//---------------------------------------------------------
 
210
//   deviceSelectionChanged
 
211
//---------------------------------------------------------
 
212
 
 
213
void MidiRawDeviceDialog::devicesSelectionChanged(QListViewItem* item)
 
214
      {
 
215
      if (item) {
 
216
            editName->setText(item->text(0));
 
217
            editPath->setText(item->text(1));
 
218
            virtPorts->setValue(item->text(3).toInt());
 
219
            speed->setCurrentItem(speed2idx(item->text(4)));
 
220
            handshaking->setCurrentItem(handshaking2int(item->text(5)));
 
221
            type->setCurrentItem(type2int(item->text(2)));
 
222
            }
 
223
      else {
 
224
            editName->setText("");
 
225
            editPath->setText("");
 
226
            virtPorts->setValue(0);
 
227
            speed->setCurrentItem(2);
 
228
            handshaking->setCurrentItem(0);
 
229
            type->setCurrentItem(1);
 
230
            }
 
231
      if (item->text(2) == "Serial Port") {
 
232
            speed->setEnabled(true);
 
233
            handshaking->setEnabled(true);
 
234
            }
 
235
      else {
 
236
            speed->setEnabled(false);
 
237
            handshaking->setEnabled(false);
 
238
            }
 
239
      }
 
240
 
 
241
//---------------------------------------------------------
 
242
//   editNameChanged
 
243
//---------------------------------------------------------
 
244
 
 
245
void MidiRawDeviceDialog::editNameChanged(const QString& text)
 
246
      {
 
247
      QListViewItem* item = listDevices->currentItem();
 
248
      if (item == 0)
 
249
            return;
 
250
      item->setText(0, text);
 
251
      }
 
252
 
 
253
//---------------------------------------------------------
 
254
//   editPathChanged
 
255
//---------------------------------------------------------
 
256
 
 
257
void MidiRawDeviceDialog::editPathChanged(const QString& text)
 
258
      {
 
259
      QListViewItem* item = listDevices->currentItem();
 
260
      if (item == 0)
 
261
            return;
 
262
      item->setText(1, text);
 
263
      }
 
264
 
 
265
//---------------------------------------------------------
 
266
//   typeChanged
 
267
//---------------------------------------------------------
 
268
 
 
269
void MidiRawDeviceDialog::typeChanged(const QString& text)
 
270
      {
 
271
      QListViewItem* item = listDevices->currentItem();
 
272
      if (item == 0)
 
273
            return;
 
274
      if (text == "Serial Port") {
 
275
            speed->setEnabled(true);
 
276
            item->setText(4, speed->currentText());
 
277
            handshaking->setEnabled(true);
 
278
            item->setText(5, handshaking->currentText());
 
279
            }
 
280
      else {
 
281
            speed->setEnabled(false);
 
282
            item->setText(4, "---");
 
283
            handshaking->setEnabled(false);
 
284
            item->setText(5, "---");
 
285
            }
 
286
      item->setText(2, text);
 
287
      }
 
288
 
 
289
//---------------------------------------------------------
 
290
//   virtPortsChanged
 
291
//---------------------------------------------------------
 
292
 
 
293
void MidiRawDeviceDialog::virtPortsChanged(int val)
 
294
      {
 
295
      QListViewItem* item = listDevices->currentItem();
 
296
      if (item == 0)
 
297
            return;
 
298
      QString s;
 
299
      s.setNum(val);
 
300
      item->setText(3, s);
 
301
      }
 
302
 
 
303
//---------------------------------------------------------
 
304
//   speedChanged
 
305
//---------------------------------------------------------
 
306
 
 
307
void MidiRawDeviceDialog::speedChanged(const QString& text)
 
308
      {
 
309
      QListViewItem* item = listDevices->currentItem();
 
310
      if (item == 0)
 
311
            return;
 
312
      item->setText(4, text);
 
313
      }
 
314
 
 
315
//---------------------------------------------------------
 
316
//   handshakingChanged
 
317
//---------------------------------------------------------
 
318
 
 
319
void MidiRawDeviceDialog::handshakingChanged(const QString& text)
 
320
      {
 
321
      QListViewItem* item = listDevices->currentItem();
 
322
      if (item == 0)
 
323
            return;
 
324
      item->setText(5, text);
 
325
      }
 
326
 
 
327
//---------------------------------------------------------
 
328
//   deviceNew
 
329
//---------------------------------------------------------
 
330
 
 
331
void MidiRawDeviceDialog::deviceNew()
 
332
      {
 
333
      QListViewItem* item = new QListViewItem(listDevices, "", "", "Serial Port", "1", "38400", "None");
 
334
      listDevices->setCurrentItem(item);
 
335
      editName->setText("");
 
336
      editPath->setText("");
 
337
      virtPorts->setValue(0);
 
338
      speed->setCurrentItem(2);
 
339
      handshaking->setCurrentItem(0);
 
340
      type->setCurrentItem(1);
 
341
 
 
342
      buttonDeviceDelete->setEnabled(true);
 
343
      editName->setEnabled(true);
 
344
      editPath->setEnabled(true);
 
345
      virtPorts->setEnabled(true);
 
346
      speed->setEnabled(true);
 
347
      handshaking->setEnabled(true);
 
348
      type->setEnabled(true);
 
349
      }
 
350
 
 
351
//---------------------------------------------------------
 
352
//   deviceDelete
 
353
//---------------------------------------------------------
 
354
 
 
355
void MidiRawDeviceDialog::deviceDelete()
 
356
      {
 
357
      QListViewItem* item = listDevices->currentItem();
 
358
      if (item == 0)
 
359
            return;
 
360
      if (deleteSerialDevice(item->text(1))) {
 
361
            printf("CANNOT DELETE DEVICE<%s>: device busy\n",
 
362
               item->text(0).latin1());
 
363
            }
 
364
      else {
 
365
            delete item;
 
366
            }
 
367
      if (listDevices->childCount() == 0) {
 
368
            buttonDeviceDelete->setEnabled(false);
 
369
            editName->setEnabled(false);
 
370
            editPath->setEnabled(false);
 
371
            virtPorts->setEnabled(false);
 
372
            speed->setEnabled(false);
 
373
            handshaking->setEnabled(false);
 
374
            type->setEnabled(false);
 
375
            }
 
376
      }
 
377
 
 
378
//---------------------------------------------------------
 
379
//   accept
 
380
//---------------------------------------------------------
 
381
 
 
382
void MidiRawDeviceDialog::accept()
 
383
      {
 
384
      QListViewItem* item = listDevices->firstChild();
 
385
 
 
386
      while (item) {
 
387
            iSerialDevice i;
 
388
            for (i = serialDevices.begin(); i != serialDevices.end(); ++i) {
 
389
                  if ((*i)->path() == item->text(1)) {
 
390
                        break;
 
391
                        }
 
392
                  }
 
393
            if (i != serialDevices.end()) {
 
394
                  (*i)->setName(item->text(0));
 
395
                  (*i)->setType(SerialType(type2int(item->text(2))));
 
396
                  (*i)->setVports(item->text(3).toInt());
 
397
                  (*i)->setSpeed(speed2int(item->text(4)));
 
398
                  (*i)->setHandshaking(handshaking2int(item->text(5)));
 
399
                  }
 
400
            else {
 
401
                  SerialDevice* port = new SerialDevice;
 
402
                  port->setName(item->text(0));
 
403
                  port->setPath(item->text(1));
 
404
                  port->setType(SerialType(type2int(item->text(2))));
 
405
                  port->setVports(item->text(3).toInt());
 
406
                  port->setSpeed(speed2int(item->text(4)));
 
407
                  port->setHandshaking(handshaking2int(item->text(5)));
 
408
                  serialDevices.push_back(port);
 
409
                  for (int i = 0; i < port->vports(); ++i) {
 
410
                        QString name = port->name();
 
411
                        if (port->vports() > 1) {
 
412
                              QString pn;
 
413
                              pn.setNum(i+1);
 
414
                              name += "-" + pn;
 
415
                              }
 
416
                        MidiSerialDevice* dev = new MidiSerialDevice(port, i, name);
 
417
                        dev->setrwFlags(0x3);
 
418
                        midiDevices.add(dev);
 
419
                        }
 
420
                  }
 
421
            item = item->nextSibling();
 
422
            }
 
423
      close();
 
424
      }
 
425
 
 
426
//---------------------------------------------------------
 
427
//   devicePath
 
428
//---------------------------------------------------------
 
429
 
 
430
void MidiRawDeviceDialog::devicePath()
 
431
      {
 
432
      QString s;
 
433
      if (editName->text().isEmpty())
 
434
            s = "/dev";
 
435
      else
 
436
            s = editName->text();
 
437
      s = QFileDialog::getOpenFileName(s, 0, this, "midiRawDevicePathDialog");
 
438
      if (!s.isEmpty())
 
439
            editName->setText(s);
 
440
      }
 
441
 
 
442
//---------------------------------------------------------
 
443
//   rbClicked
 
444
//---------------------------------------------------------
 
445
 
 
446
void MPConfig::rbClicked(QListViewItem* item, const QPoint&, int col)
 
447
      {
 
448
      if (item == 0)
 
449
            return;
 
450
      QString id = item->text(DEVCOL_NO);
 
451
      int no = atoi(id.latin1()) - 1;
 
452
      if (no < 0 || no >= MIDI_PORTS)
 
453
            return;
 
454
 
 
455
      int n;
 
456
      MidiPort* port      = &midiPorts[no];
 
457
      int flags           = port->rwFlags();
 
458
      MidiDevice* dev     = port->device();
 
459
      QListView* listView = item->listView();
 
460
      QPoint ppt = listView->itemRect(item).bottomLeft();
 
461
      ppt += QPoint(listView->header()->sectionPos(col), listView->header()->height());
 
462
      ppt  = listView->mapToGlobal(ppt);
 
463
 
 
464
      switch (col) {
 
465
            case DEVCOL_GUI:
 
466
                  if (dev == 0)
 
467
                        break;
 
468
                  if (port->hasGui()) {
 
469
                        port->showGui(!port->guiVisible());
 
470
                        item->setPixmap(DEVCOL_GUI, port->guiVisible() ? *dotIcon : *dothIcon);
 
471
                        }
 
472
                  break;
 
473
 
 
474
            case DEVCOL_REC:
 
475
                  if (dev == 0)
 
476
                        break;
 
477
                  flags ^= 0x2;
 
478
                  port->setrwFlags(flags);
 
479
                  item->setPixmap(DEVCOL_REC, (port->rwFlags() & 0x2) ? *dotIcon : QPixmap());
 
480
                  midiThread->setMidiDevice(port, dev);
 
481
                  break;
 
482
            case DEVCOL_NAME:
 
483
                  {
 
484
                  if (popup == 0)
 
485
                        popup = new QPopupMenu(this);
 
486
                  popup->clear();
 
487
                  popup->insertItem(tr("none"), 0);
 
488
                  int id = 1;
 
489
                  for (iMidiDevice i = midiDevices.begin(); i != midiDevices.end(); ++i) {
 
490
                        const QString s = (*i)->name();
 
491
                        popup->insertItem(s, id);
 
492
                        for (int k = 0; k < MIDI_PORTS; ++k) {
 
493
                              MidiDevice* dev = midiPorts[k].device();
 
494
                              if (dev && s == dev->name()) {
 
495
                                    popup->setItemEnabled(id, false);
 
496
                                    break;
 
497
                                    }
 
498
                              }
 
499
                        ++id;
 
500
                        }
 
501
                  popup->insertItem(tr("other raw ..."), 999);
 
502
                  n = popup->exec(ppt, 0);
 
503
                  if (n == -1)
 
504
                        break;
 
505
                  if (n == 999) {
 
506
                        //-------------------------------------------
 
507
                        // other raw device
 
508
                        //-------------------------------------------
 
509
                        if (rdDialog == 0) {
 
510
                              rdDialog = new MidiRawDeviceDialog();
 
511
                              }
 
512
                        rdDialog->populate();
 
513
                        rdDialog->show();
 
514
                        break;
 
515
                        }
 
516
                  QString s = popup->text(n);
 
517
                  item->setText(DEVCOL_NAME, s);
 
518
                  if (n > 0) {
 
519
                        MidiDevice* dev = midiDevices.find(s);
 
520
                        if (dev) {
 
521
                              port->setrwFlags(dev->rwFlags());
 
522
                              item->setPixmap(DEVCOL_REC, (port->rwFlags() & 0x2) ? *dotIcon : QPixmap());
 
523
                              item->setText(DEVCOL_STATE, port->state());
 
524
                              }
 
525
                        midiThread->setMidiDevice(port, dev);
 
526
                        iSynthI ii;
 
527
                        for (ii = synthiInstances.begin(); ii != synthiInstances.end(); ++ii) {
 
528
                              if ((*ii)->iname() == dev->name()) {
 
529
//                                    midiInstruments.push_back(*ii);
 
530
                                    port->setInstrument(*ii);
 
531
                                    (*ii)->setDevice(dev);
 
532
printf("set Device midi %p\n", dev);
 
533
                                    break;
 
534
                                    }
 
535
                              }
 
536
                        }
 
537
                  else {
 
538
                        midiThread->setMidiDevice(port, 0);
 
539
                        item->setPixmap(DEVCOL_REC, QPixmap());
 
540
                        }
 
541
                  item->setText(DEVCOL_STATE, port->state());
 
542
                  song->update();
 
543
                  }
 
544
                  break;
 
545
 
 
546
            case DEVCOL_INSTR:
 
547
                  {
 
548
                  if (instrPopup == 0)
 
549
                        instrPopup = new QPopupMenu(this);
 
550
                  instrPopup->clear();
 
551
                  for (iMidiInstrument i = midiInstruments.begin(); i
 
552
                     != midiInstruments.end(); ++i) {
 
553
                        instrPopup->insertItem((*i)->iname());
 
554
                        }
 
555
                  n = instrPopup->exec(ppt, 0);
 
556
                  if (n == -1)
 
557
                        break;
 
558
                  QString s = instrPopup->text(n);
 
559
                  item->setText(DEVCOL_INSTR, s);
 
560
                  for (iMidiInstrument i = midiInstruments.begin(); i
 
561
                     != midiInstruments.end(); ++i) {
 
562
                        if ((*i)->iname() == s) {
 
563
                              port->setInstrument(*i);
 
564
                              break;
 
565
                              }
 
566
                        }
 
567
                  song->update();
 
568
                  }
 
569
                  break;
 
570
 
 
571
            }
 
572
      }
 
573
 
 
574
//---------------------------------------------------------
 
575
//   MPWhatsThis::text
 
576
//---------------------------------------------------------
 
577
 
 
578
QString MPWhatsThis::text(const QPoint& pos)
 
579
      {
 
580
      int n = header->cellAt(pos.x());
 
581
      if (n == -1)
 
582
            return 0;
 
583
      switch (header->mapToLogical(n)) {
 
584
            case DEVCOL_NO:
 
585
                  return header->tr("Port Number");
 
586
            case DEVCOL_GUI:
 
587
                  return header->tr("enable gui for device");
 
588
            case DEVCOL_REC:
 
589
                  return header->tr("enables recording from the device");
 
590
            case DEVCOL_NAME:
 
591
                  return header->tr("Name of the midi device associated with"
 
592
                       " this port number");
 
593
            case DEVCOL_INSTR:
 
594
                  return header->tr("Instrument connected to port");
 
595
            case DEVCOL_STATE:
 
596
                  return header->tr("State: result of opening the device");
 
597
            default:
 
598
                  break;
 
599
            }
 
600
      return 0;
 
601
      }
 
602
 
 
603
//---------------------------------------------------------
 
604
//   MPConfig
 
605
//    Midi Port Config
 
606
//---------------------------------------------------------
 
607
 
 
608
MPConfig::MPConfig()
 
609
   : QWidget(0, "midiPortTable",
 
610
   WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_ContextHelp)
 
611
      {
 
612
      popup      = 0;
 
613
      instrPopup = 0;
 
614
      rdDialog   = 0;
 
615
 
 
616
      setCaption(tr("MusE: Midi Port Table"));
 
617
      QVBoxLayout* box = new QVBoxLayout(this);
 
618
      mdevView  = new QListView(this);
 
619
      mdevView->setSorting(-1);
 
620
      mdevView->setAllColumnsShowFocus(true);
 
621
      mdevView->addColumn("Port",   40);
 
622
      mdevView->addColumn("GUI",    40);
 
623
      mdevView->addColumn("Rec",    40);
 
624
      mdevView->addColumn("Instrument", 110);
 
625
      mdevView->addColumn("Device Name", 110);
 
626
      mdevView->addColumn("State");
 
627
      mdevView->setColumnWidthMode(3, QListView::Maximum);
 
628
      mdevView->setColumnAlignment(0, AlignCenter);
 
629
      mdevView->setFocusPolicy(NoFocus);
 
630
 
 
631
      mdevView->setColumnAlignment(DEVCOL_NO, AlignRight);
 
632
      mdevView->setColumnAlignment(DEVCOL_GUI, AlignCenter);
 
633
      mdevView->setColumnAlignment(DEVCOL_REC, AlignCenter);
 
634
      mdevView->header()->setResizeEnabled(false, DEVCOL_NO);
 
635
      mdevView->header()->setResizeEnabled(false, DEVCOL_REC);
 
636
      mdevView->header()->setResizeEnabled(false, DEVCOL_GUI);
 
637
      mdevView->setResizeMode(QListView::LastColumn);
 
638
 
 
639
      new MPWhatsThis(mdevView, mdevView->header());
 
640
 
 
641
      songChanged(0);
 
642
 
 
643
      box->addWidget(mdevView, 10);
 
644
      connect(mdevView, SIGNAL(pressed(QListViewItem*,const QPoint&,int)),
 
645
         this, SLOT(rbClicked(QListViewItem*,const QPoint&,int)));
 
646
      connect(song, SIGNAL(songChanged(int)), SLOT(songChanged(int)));
 
647
      }
 
648
 
 
649
//---------------------------------------------------------
 
650
//   songChanged
 
651
//---------------------------------------------------------
 
652
 
 
653
void MPConfig::songChanged(int)
 
654
      {
 
655
      mdevView->clear();
 
656
      for (int i = MIDI_PORTS-1; i >= 0; --i) {
 
657
            MidiPort* port  = &midiPorts[i];
 
658
            MidiDevice* dev = port->device();
 
659
            QString s;
 
660
            s.setNum(i+1);
 
661
            QListViewItem* item = new QListViewItem(mdevView);
 
662
            item->setText(DEVCOL_NO, s);
 
663
            item->setText(DEVCOL_STATE, port->state());
 
664
            if (port->instrument())
 
665
                  item->setText(DEVCOL_INSTR, port->instrument()->iname());
 
666
            else
 
667
                  item->setText(DEVCOL_INSTR, "unknown");
 
668
            if (dev) {
 
669
                  item->setText(DEVCOL_NAME, dev->name());
 
670
                  if (port->rwFlags() & 0x2)
 
671
                        item->setPixmap(DEVCOL_REC, *dotIcon);
 
672
                  }
 
673
            else {
 
674
                  item->setText(DEVCOL_NAME, "none");
 
675
                  item->setPixmap(DEVCOL_GUI, *dothIcon);
 
676
                  }
 
677
            if (port->hasGui()) {
 
678
                  item->setPixmap(DEVCOL_GUI, port->guiVisible() ? *dotIcon : *dothIcon);
 
679
                  }
 
680
            else {
 
681
                  item->setPixmap(DEVCOL_GUI, QPixmap());
 
682
                  }
 
683
            item->setPixmap(DEVCOL_INSTR, *buttondownIcon);
 
684
            item->setPixmap(DEVCOL_NAME, *buttondownIcon);
 
685
            mdevView->insertItem(item);
 
686
            }
 
687
      }
 
688
 
 
689
//---------------------------------------------------------
 
690
//   configMidiPorts
 
691
//---------------------------------------------------------
 
692
 
 
693
void MusE::configMidiPorts()
 
694
      {
 
695
      if (!midiPortConfig)
 
696
            midiPortConfig = new MPConfig();
 
697
      midiPortConfig->show();
 
698
      }
 
699