~ubuntu-branches/ubuntu/lucid/kmidimon/lucid

« back to all changes in this revision

Viewing changes to src/kmidimon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Nick Ellery
  • Date: 2009-08-10 18:45:19 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090810184519-9q6ouf7i7708ni7s
Tags: 0.7.1-0ubuntu1
* New upstream release (LP: #411739).
  - Optionally translate notes, controllers and program numbers into names.
  - Support for GM, GS and XG standards, using .INS definition files.
  - New context menu option: adjust column sizes.
  - Fine grained event filters, in addition to the old coarse filters.
  - Fixed unregistered bug: don't change the current sequence PPQ/Tempo when 
    applying the preferences dialog.
  - New dialog showing information about the current loaded sequence.
  - Support for the SMF events: Sequence Number, Forced Channel, Forced Port 
    and SMPTE Offset.
  - Playback speed control: tempo "zoom" slider allowing continuous scaling 
    from 50% to 200%.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <QTextStream>
28
28
#include <QSignalMapper>
29
29
#include <QVariant>
 
30
#include <QToolTip>
30
31
 
31
32
#include <klocale.h>
32
33
#include <kaction.h>
45
46
#include <kinputdialog.h>
46
47
#include <kprogressdialog.h>
47
48
#include <krecentfilesaction.h>
 
49
#include <kmenubar.h>
 
50
#include <kmessagebox.h>
48
51
 
49
52
#include "kmidimon.h"
50
53
#include "configdialog.h"
51
54
#include "connectdlg.h"
52
55
#include "sequencemodel.h"
53
56
#include "proxymodel.h"
 
57
#include "eventfilter.h"
 
58
#include "sequenceradaptor.h"
 
59
#include "slideraction.h"
54
60
 
55
61
KMidimon::KMidimon() :
56
62
    KXmlGuiWindow(0)
68
74
    m_view->setAlternatingRowColors(true);
69
75
    m_view->setModel(m_proxy);
70
76
    m_view->setSortingEnabled(false);
71
 
    //QAbstractItemView::NoSelection
72
77
    m_view->setSelectionMode(QAbstractItemView::SingleSelection);
73
78
    connect( m_view->selectionModel(),
74
79
             SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
193
198
    actionCollection()->addAction("rewind", m_rewind);
194
199
 
195
200
    m_record = new KAction(this);
196
 
    m_record->setText(i18n("&Record"));
 
201
    m_record->setText(i18n("Record"));
197
202
    m_record->setIcon(KIcon("media-record"));
198
203
    m_record->setShortcut( Qt::Key_R );
199
204
    m_record->setWhatsThis(i18n("Append new recorded events to the current session"));
201
206
    actionCollection()->addAction("record", m_record);
202
207
 
203
208
    m_stop = new KAction(this);
204
 
    m_stop->setText( i18n("&Stop") );
 
209
    m_stop->setText( i18n("Stop") );
205
210
    m_stop->setIcon(KIcon("media-playback-stop"));
206
211
    m_stop->setShortcut( Qt::Key_S );
207
212
    m_stop->setWhatsThis(i18n("Stop playback or recording"));
209
214
    actionCollection()->addAction("stop", m_stop);
210
215
 
211
216
    m_connectAll = new KAction(this);
212
 
    m_connectAll->setText(i18n("&Connect All Inputs"));
 
217
    m_connectAll->setText(i18n("Connect All Inputs"));
213
218
    m_connectAll->setWhatsThis(i18n("Connect all readable MIDI ports"));
214
219
    connect(m_connectAll, SIGNAL(triggered()), SLOT(connectAll()));
215
220
    actionCollection()->addAction("connect_all", m_connectAll);
216
221
 
217
222
    m_disconnectAll = new KAction(this);
218
 
    m_disconnectAll->setText(i18n("&Disconnect All Inputs"));
 
223
    m_disconnectAll->setText(i18n("Disconnect All Inputs"));
219
224
    m_disconnectAll->setWhatsThis(i18n("Disconnect all input MIDI ports"));
220
225
    connect(m_disconnectAll, SIGNAL(triggered()), SLOT(disconnectAll()));
221
226
    actionCollection()->addAction( "disconnect_all", m_disconnectAll );
222
227
 
223
228
    m_configConns = new KAction(this);
224
 
    m_configConns->setText(i18n("Con&figure Connections"));
 
229
    m_configConns->setText(i18n("Configure Connections"));
225
230
    m_configConns->setWhatsThis(i18n("Open the Connections dialog"));
226
231
    connect(m_configConns, SIGNAL(triggered()), SLOT(configConnections()));
227
232
    actionCollection()->addAction("connections_dialog", m_configConns );
228
233
 
229
234
    m_createTrack = new KAction(this);
230
 
    m_createTrack->setText(i18n("&Add Track View"));
 
235
    m_createTrack->setText(i18n("Add Track View"));
231
236
    m_createTrack->setWhatsThis(i18n("Create a new tab/track view"));
232
237
    connect(m_createTrack, SIGNAL(triggered()), SLOT(addTrack()));
233
238
    actionCollection()->addAction("add_track", m_createTrack );
234
239
 
235
240
    m_changeTrack = new KAction(this);
236
 
    m_changeTrack->setText(i18n("&Change Track View"));
 
241
    m_changeTrack->setText(i18n("Change Track View"));
237
242
    m_changeTrack->setWhatsThis(i18n("Change the track number of the view"));
238
243
    connect(m_changeTrack, SIGNAL(triggered()), SLOT(changeCurrentTrack()));
239
244
    actionCollection()->addAction("change_track", m_changeTrack );
240
245
 
241
246
    m_deleteTrack = new KAction(this);
242
 
    m_deleteTrack->setText(i18n("&Delete Track View"));
 
247
    m_deleteTrack->setText(i18n("Delete Track View"));
243
248
    m_deleteTrack->setWhatsThis(i18n("Delete the tab/track view"));
244
249
    connect(m_deleteTrack, SIGNAL(triggered()), SLOT(deleteCurrentTrack()));
245
250
    actionCollection()->addAction("delete_track", m_deleteTrack );
246
251
 
247
 
    for(int i = 0; i < COLUMN_COUNT; ++i ) {
 
252
    for ( int i = 0; i < COLUMN_COUNT; ++i ) {
248
253
        m_popupAction[i] = new KToggleAction(columnName[i], this);
249
254
        m_popupAction[i]->setWhatsThis(i18n("Toggle the %1 column",columnName[i]));
250
255
        connect(m_popupAction[i], SIGNAL(triggered()), m_mapper, SLOT(map()));
253
258
    }
254
259
    connect(m_mapper, SIGNAL(mapped(int)), SLOT(toggleColumn(int)));
255
260
 
 
261
    m_resizeColumns = new KAction(this);
 
262
    m_resizeColumns->setText(i18n("Resize columns"));
 
263
    m_resizeColumns->setWhatsThis(i18n("Resize the columns width to fit it's contents"));
 
264
    connect(m_resizeColumns, SIGNAL(triggered()), SLOT(resizeAllColumns()));
 
265
    actionCollection()->addAction("resize_columns", m_resizeColumns);
 
266
 
 
267
    m_fileInfo = new KAction(this);
 
268
    m_fileInfo->setText(i18n("Sequence Info"));
 
269
    m_fileInfo->setWhatsThis(i18n("Display information about the loaded sequence"));
 
270
    m_fileInfo->setIcon(KIcon("dialog-information"));
 
271
    connect(m_fileInfo, SIGNAL(triggered()), SLOT(songFileInfo()));
 
272
    actionCollection()->addAction("file_info", m_fileInfo);
 
273
 
 
274
    m_tempoSlider = new KPlayerPopupSliderAction( this, SLOT(tempoSlider(int)), this );
 
275
    m_tempoSlider->setText(i18n("Scale Tempo"));
 
276
    m_tempoSlider->setWhatsThis(i18n("Display a slider to scale the tempo between 50% and 200%"));
 
277
    m_tempoSlider->setIcon(KIcon("chronometer"));
 
278
    actionCollection()->addAction("tempo_slider", m_tempoSlider);
 
279
 
 
280
    m_tempo100 = new KAction(this);
 
281
    m_tempo100->setText(i18n("Reset Tempo"));
 
282
    m_tempo100->setWhatsThis(i18n("Reset the tempo scale to 100%"));
 
283
    m_tempo100->setIcon(KIcon("player-time"));
 
284
    connect(m_tempo100, SIGNAL(triggered()), this, SLOT(tempoReset()));
 
285
    actionCollection()->addAction("tempo100", m_tempo100);
 
286
 
256
287
    setStandardToolBarMenuEnabled(true);
257
288
    setupGUI();
258
289
 
259
290
    m_popup = static_cast <QMenu*>(guiFactory()->container("popup", this));
260
291
    Q_CHECK_PTR( m_popup );
 
292
 
 
293
    m_filter = new EventFilter(this);
 
294
    QMenu* filtersMenu = m_filter->buildMenu(this);
 
295
    m_popup->addMenu( filtersMenu );
 
296
    m_model->setFilter(m_filter);
 
297
    m_proxy->setFilter(m_filter);
 
298
    connect(m_filter, SIGNAL(filterChanged()), m_proxy, SLOT(invalidate()));
 
299
    menuBar()->insertMenu( menuBar()->actions().last(), filtersMenu );
261
300
}
262
301
 
263
302
void KMidimon::fileNew()
264
303
{
 
304
    m_file.clear();
265
305
    m_model->clear();
266
306
    for (int i = m_tabBar->count() - 1; i >= 0; i--) {
267
307
        m_tabBar->removeTab(i);
275
315
    m_adaptor->setResolution(m_defaultResolution);
276
316
    m_adaptor->queue_set_tempo();
277
317
    m_adaptor->rewind();
 
318
    tempoReset();
278
319
    updateView();
279
320
}
280
321
 
285
326
        QFileInfo finfo(path);
286
327
        if (finfo.exists()) {
287
328
            try {
 
329
                m_file = path;
288
330
                m_view->blockSignals(true);
289
331
                stop();
290
332
                m_model->clear();
316
358
                m_model->setCurrentTrack(0);
317
359
                for (int i = 0; i < COLUMN_COUNT; ++i)
318
360
                    m_view->resizeColumnToContents(i);
 
361
                tempoReset();
319
362
            } catch (...) {
320
363
                m_model->clear();
321
364
            }
373
416
    config.writeEntry("smf", m_proxy->showSmfMsg());
374
417
    config.writeEntry("client_names", m_model->showClientNames());
375
418
    config.writeEntry("translate_sysex", m_model->translateSysex());
 
419
    config.writeEntry("translate_notes", m_model->translateNotes());
 
420
    config.writeEntry("translate_ctrls", m_model->translateCtrls());
 
421
    config.writeEntry("instrument", m_model->getInstrumentName());
376
422
    config.writeEntry("fixed_font", getFixedFont());
377
423
    for (i = 0; i < COLUMN_COUNT; ++i) {
378
424
        config.writeEntry(QString("show_column_%1").arg(i),
384
430
    config = KGlobal::config()->group("RecentFiles");
385
431
    m_recentFiles->saveEntries(config);
386
432
    config.sync();
 
433
 
 
434
    m_filter->saveConfiguration();
387
435
}
388
436
 
389
437
void KMidimon::readConfiguration()
399
447
    m_proxy->setFilterSmfMsg(config.readEntry("smf", true));
400
448
    m_model->setShowClientNames(config.readEntry("client_names", false));
401
449
    m_model->setTranslateSysex(config.readEntry("translate_sysex", false));
402
 
    m_adaptor->setResolution(m_defaultResolution = config.readEntry("resolution", RESOLUTION));
403
 
    m_adaptor->setTempo(m_defaultTempo = config.readEntry("tempo", TEMPO_BPM));
 
450
    m_model->setTranslateNotes(config.readEntry("translate_notes", false));
 
451
    m_model->setTranslateCtrls(config.readEntry("translate_ctrls", false));
 
452
    m_model->setInstrumentName(config.readEntry("instrument", QString()));
 
453
    m_defaultResolution = config.readEntry("resolution", RESOLUTION);
 
454
    m_defaultTempo = config.readEntry("tempo", TEMPO_BPM);
 
455
    m_adaptor->setResolution(m_defaultResolution);
 
456
    m_adaptor->setTempo(m_defaultTempo);
404
457
    m_adaptor->queue_set_tempo();
405
458
    setFixedFont(config.readEntry("fixed_font", false));
406
459
    for (i = 0; i < COLUMN_COUNT; ++i) {
412
465
 
413
466
    config = KGlobal::config()->group("RecentFiles");
414
467
    m_recentFiles->loadEntries(config);
 
468
 
 
469
    m_filter->loadConfiguration();
415
470
}
416
471
 
417
472
void KMidimon::preferences()
430
485
    dlg.setRegSmfMsg(m_proxy->showSmfMsg());
431
486
    dlg.setShowClientNames(m_model->showClientNames());
432
487
    dlg.setTranslateSysex(m_model->translateSysex());
 
488
    dlg.setTranslateNotes(m_model->translateNotes());
 
489
    dlg.setTranslateCtrls(m_model->translateCtrls());
 
490
    dlg.setInstruments(m_model->getInstruments());
 
491
    dlg.setInstrumentName(m_model->getInstrumentName());
433
492
    dlg.setUseFixedFont(getFixedFont());
434
493
    for (i = 0; i < COLUMN_COUNT; ++i) {
435
494
        dlg.setShowColumn(i, m_popupAction[i]->isChecked());
445
504
        m_proxy->setFilterSmfMsg(dlg.isRegSmfMsg());
446
505
        m_model->setShowClientNames(dlg.showClientNames());
447
506
        m_model->setTranslateSysex(dlg.translateSysex());
448
 
        m_adaptor->setTempo(m_defaultTempo = dlg.getTempo());
449
 
        m_adaptor->setResolution(m_defaultResolution = dlg.getResolution());
450
 
        m_adaptor->queue_set_tempo();
 
507
        m_model->setTranslateNotes(dlg.translateNotes());
 
508
        m_model->setTranslateCtrls(dlg.translateCtrls());
 
509
        m_model->setInstrumentName(dlg.getInstrumentName());
 
510
        m_defaultTempo = dlg.getTempo();
 
511
        m_defaultResolution = dlg.getResolution();
451
512
        setFixedFont(dlg.useFixedFont());
452
513
        for (i = 0; i < COLUMN_COUNT; ++i) {
453
514
            setColumnStatus(i, dlg.showColumn(i));
584
645
 
585
646
void KMidimon::resizeColumns(const QModelIndex&, int, int)
586
647
{
 
648
        resizeAllColumns();
 
649
    m_view->scrollToBottom();
 
650
}
 
651
 
 
652
void KMidimon::resizeAllColumns()
 
653
{
587
654
    for( int i = 0; i < COLUMN_COUNT; ++i)
588
655
        m_view->resizeColumnToContents(i);
589
 
    m_view->scrollToBottom();
590
656
}
591
657
 
592
658
void KMidimon::addNewTab(int data)
692
758
    if (index.isValid())
693
759
        m_view->setCurrentIndex(m_proxy->mapFromSource(index));
694
760
}
 
761
 
 
762
void
 
763
KMidimon::songFileInfo()
 
764
{
 
765
    QString infostr;
 
766
    if (m_file.isEmpty())
 
767
        infostr = i18n("No file loaded");
 
768
    else
 
769
        infostr = i18n("File: <b>%1</b><br>"
 
770
                       "SMF Format: <b>%2</b><br>"
 
771
                       "Number of tracks: <b>%3</b><br>"
 
772
                       "Number of events: <b>%4</b><br>"
 
773
                       "Division: <b>%5 ppq</b><br>"
 
774
                       "Initial tempo: <b>%6 bpm</b><br>"
 
775
                       "Duration: <b>%7</b>",
 
776
                       m_file,
 
777
                       m_model->getSMFFormat(),
 
778
                       m_model->getSMFTracks(),
 
779
                       m_model->getSong()->size(),
 
780
                       m_model->getSMFDivision(),
 
781
                       m_model->getInitialTempo(),
 
782
                       m_model->getDuration()
 
783
                       );
 
784
    KMessageBox::information(this, infostr, i18n("Sequence Information"));
 
785
}
 
786
 
 
787
void KMidimon::tempoReset()
 
788
{
 
789
    m_adaptor->setTempoFactor(1.0);
 
790
    m_tempoSlider->slider()->setValue(100);
 
791
    m_tempoSlider->slider()->setToolTip("100%");
 
792
}
 
793
 
 
794
void KMidimon::tempoSlider(int value)
 
795
{
 
796
    double tempoFactor = (value*value + 100.0*value + 2e4) / 4e4;
 
797
    m_adaptor->setTempoFactor(tempoFactor);
 
798
    // Slider tooltip
 
799
    QString tip = QString("%1\%").arg(tempoFactor*100.0, 0, 'f', 0);
 
800
    m_tempoSlider->slider()->setToolTip(tip);
 
801
    QToolTip::showText(QCursor::pos(), tip, this);
 
802
}