📄 eventview.cpp
字号:
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: *//* Rosegarden A MIDI and audio sequencer and musical notation editor. This program is Copyright 2000-2007 Guillaume Laurent <glaurent@telegraph-road.org>, Chris Cannam <cannam@all-day-breakfast.com>, Richard Bown <richard.bown@ferventsoftware.com> The moral rights of Guillaume Laurent, Chris Cannam, and Richard Bown to claim authorship of this work have been asserted. Other copyrights also apply to some parts of this work. Please see the AUTHORS file and individual file headers for details. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information.*/#include "EventView.h"#include "EventViewItem.h"#include "TrivialVelocityDialog.h"#include "base/BaseProperties.h"#include "misc/Debug.h"#include "misc/Strings.h"#include "base/Clipboard.h"#include "base/Event.h"#include "base/MidiTypes.h"#include "base/NotationTypes.h"#include "base/RealTime.h"#include "base/Segment.h"#include "base/SegmentPerformanceHelper.h"#include "base/Selection.h"#include "base/Track.h"#include "base/TriggerSegment.h"#include "commands/edit/CopyCommand.h"#include "commands/edit/CutCommand.h"#include "commands/edit/EraseCommand.h"#include "commands/edit/EventEditCommand.h"#include "commands/edit/PasteEventsCommand.h"#include "commands/edit/EventInsertionCommand.h"#include "commands/segment/SegmentLabelCommand.h"#include "commands/segment/SetTriggerSegmentBasePitchCommand.h"#include "commands/segment/SetTriggerSegmentBaseVelocityCommand.h"#include "commands/segment/SetTriggerSegmentDefaultRetuneCommand.h"#include "commands/segment/SetTriggerSegmentDefaultTimeAdjustCommand.h"#include "document/RosegardenGUIDoc.h"#include "document/ConfigGroups.h"#include "gui/dialogs/EventEditDialog.h"#include "gui/dialogs/PitchDialog.h"#include "gui/dialogs/SimpleEventEditDialog.h"#include "gui/general/EditViewBase.h"#include "gui/general/MidiPitchLabel.h"#include "gui/kdeext/KTmpStatusMsg.h"#include "gui/dialogs/EventFilterDialog.h"#include <kaction.h>#include <kconfig.h>#include <klocale.h>#include <kstatusbar.h>#include <kstddirs.h>#include <kglobal.h>#include <klineeditdlg.h>#include <klistview.h>#include <kxmlguiclient.h>#include <qbuttongroup.h>#include <qcanvas.h>#include <qcheckbox.h>#include <qdialog.h>#include <qframe.h>#include <qgroupbox.h>#include <qiconset.h>#include <qlabel.h>#include <qlayout.h>#include <qlistview.h>#include <qpixmap.h>#include <qpoint.h>#include <qpopupmenu.h>#include <qpushbutton.h>#include <qsize.h>#include <qstring.h>#include <qwidget.h>#include <algorithm>namespace Rosegarden{intEventView::m_lastSetEventFilter = -1;EventView::EventView(RosegardenGUIDoc *doc, std::vector<Segment *> segments, QWidget *parent): EditViewBase(doc, segments, 2, parent, "eventview"), m_eventFilter(Note | Text | SystemExclusive | Controller | ProgramChange | PitchBend | Indication | Other), m_menu(0){ m_isTriggerSegment = false; m_triggerName = m_triggerPitch = m_triggerVelocity = 0; if (!segments.empty()) { Segment *s = *segments.begin(); if (s->getComposition()) { int id = s->getComposition()->getTriggerSegmentId(s); if (id >= 0) m_isTriggerSegment = true; } } if (m_lastSetEventFilter < 0) m_lastSetEventFilter = m_eventFilter; else m_eventFilter = m_lastSetEventFilter; initStatusBar(); setupActions(); // define some note filtering buttons in a group // m_filterGroup = new QButtonGroup(1, Horizontal, i18n("Event filters"), getCentralWidget()); m_noteCheckBox = new QCheckBox(i18n("Note"), m_filterGroup); m_programCheckBox = new QCheckBox(i18n("Program Change"), m_filterGroup); m_controllerCheckBox = new QCheckBox(i18n("Controller"), m_filterGroup); m_pitchBendCheckBox = new QCheckBox(i18n("Pitch Bend"), m_filterGroup); m_sysExCheckBox = new QCheckBox(i18n("System Exclusive"), m_filterGroup); m_keyPressureCheckBox = new QCheckBox(i18n("Key Pressure"), m_filterGroup); m_channelPressureCheckBox = new QCheckBox(i18n("Channel Pressure"), m_filterGroup); m_restCheckBox = new QCheckBox(i18n("Rest"), m_filterGroup); m_indicationCheckBox = new QCheckBox(i18n("Indication"), m_filterGroup); m_textCheckBox = new QCheckBox(i18n("Text"), m_filterGroup); m_otherCheckBox = new QCheckBox(i18n("Other"), m_filterGroup); m_grid->addWidget(m_filterGroup, 2, 0); // Connect up // connect(m_filterGroup, SIGNAL(released(int)), SLOT(slotModifyFilter(int))); m_eventList = new KListView(getCentralWidget()); m_eventList->setItemsRenameable(true); m_grid->addWidget(m_eventList, 2, 1); if (m_isTriggerSegment) { int id = segments[0]->getComposition()->getTriggerSegmentId(segments[0]); TriggerSegmentRec *rec = segments[0]->getComposition()->getTriggerSegmentRec(id); QGroupBox *groupBox = new QGroupBox (1, Horizontal, i18n("Triggered Segment Properties"), getCentralWidget()); QFrame *frame = new QFrame(groupBox); QGridLayout *layout = new QGridLayout(frame, 5, 3, 5, 5); layout->addWidget(new QLabel(i18n("Label: "), frame), 0, 0); QString label = strtoqstr(segments[0]->getLabel()); if (label == "") label = i18n("<no label>"); m_triggerName = new QLabel(label, frame); layout->addWidget(m_triggerName, 0, 1); QPushButton *editButton = new QPushButton(i18n("edit"), frame); layout->addWidget(editButton, 0, 2); connect(editButton, SIGNAL(clicked()), this, SLOT(slotEditTriggerName())); layout->addWidget(new QLabel(i18n("Base pitch: "), frame), 1, 0); m_triggerPitch = new QLabel(QString("%1").arg(rec->getBasePitch()), frame); layout->addWidget(m_triggerPitch, 1, 1); editButton = new QPushButton(i18n("edit"), frame); layout->addWidget(editButton, 1, 2); connect(editButton, SIGNAL(clicked()), this, SLOT(slotEditTriggerPitch())); layout->addWidget(new QLabel(i18n("Base velocity: "), frame), 2, 0); m_triggerVelocity = new QLabel(QString("%1").arg(rec->getBaseVelocity()), frame); layout->addWidget(m_triggerVelocity, 2, 1); editButton = new QPushButton(i18n("edit"), frame); layout->addWidget(editButton, 2, 2); connect(editButton, SIGNAL(clicked()), this, SLOT(slotEditTriggerVelocity())); /*!!! Comment out these two options, which are not yet used anywhere else -- intended for use with library ornaments, not yet implemented layout->addWidget(new QLabel(i18n("Default timing: "), frame), 3, 0); KComboBox *adjust = new KComboBox(frame); layout->addMultiCellWidget(adjust, 3, 3, 1, 2); adjust->insertItem(i18n("As stored")); adjust->insertItem(i18n("Truncate if longer than note")); adjust->insertItem(i18n("End at same time as note")); adjust->insertItem(i18n("Stretch or squash segment to note duration")); std::string timing = rec->getDefaultTimeAdjust(); if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_NONE) { adjust->setCurrentItem(0); } else if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_SQUISH) { adjust->setCurrentItem(3); } else if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_SYNC_START) { adjust->setCurrentItem(1); } else if (timing == BaseProperties::TRIGGER_SEGMENT_ADJUST_SYNC_END) { adjust->setCurrentItem(2); } connect(adjust, SIGNAL(activated(int)), this, SLOT(slotTriggerTimeAdjustChanged(int))); QCheckBox *retune = new QCheckBox(i18n("Adjust pitch to trigger note by default"), frame); retune->setChecked(rec->getDefaultRetune()); connect(retune, SIGNAL(clicked()), this, SLOT(slotTriggerRetuneChanged())); layout->addMultiCellWidget(retune, 4, 4, 1, 2); */ m_grid->addWidget(groupBox, 2, 2); } updateViewCaption(); for (unsigned int i = 0; i < m_segments.size(); ++i) { m_segments[i]->addObserver(this); } // Connect double clicker // connect(m_eventList, SIGNAL(doubleClicked(QListViewItem*)), SLOT(slotPopupEventEditor(QListViewItem*))); connect(m_eventList, SIGNAL(rightButtonPressed(QListViewItem*, const QPoint&, int)), SLOT(slotPopupMenu(QListViewItem*, const QPoint&, int))); m_eventList->setAllColumnsShowFocus(true); m_eventList->setSelectionMode(QListView::Extended); m_eventList->addColumn(i18n("Time ")); m_eventList->addColumn(i18n("Duration ")); m_eventList->addColumn(i18n("Event Type ")); m_eventList->addColumn(i18n("Pitch ")); m_eventList->addColumn(i18n("Velocity ")); m_eventList->addColumn(i18n("Type (Data1) ")); m_eventList->addColumn(i18n("Value (Data2) ")); for (int col = 0; col < m_eventList->columns(); ++col) m_eventList->setRenameable(col, true); readOptions(); setButtonsToFilter(); applyLayout(); makeInitialSelection(doc->getComposition().getPosition()); slotCompositionStateUpdate(); setOutOfCtor();}EventView::~EventView(){ for (unsigned int i = 0; i < m_segments.size(); ++i) { RG_DEBUG << "~EventView - removing this observer from " << m_segments[i] << endl; m_segments[i]->removeObserver(this); }}voidEventView::eventRemoved(const Segment *, Event *e){ m_deletedEvents.insert(e);}voidEventView::segmentDeleted(const Segment *s){ std::vector<Segment *>::iterator i = std::find(m_segments.begin(), m_segments.end(), s); if (i != m_segments.end()) { m_segments.erase(i); } else { RG_DEBUG << "%%% WARNING - EventView::segmentDeleted() called on non-registered segment - should not happen\n"; }}boolEventView::applyLayout(int /*staffNo*/){ // If no selection has already been set then we copy what's // already set and try to replicate this after the rebuild // of the view. // if (m_listSelection.size() == 0) { QPtrList<QListViewItem> selection = m_eventList->selectedItems(); if (selection.count()) { QPtrListIterator<QListViewItem> it(selection); QListViewItem *listItem; while ((listItem = it.current()) != 0) { m_listSelection.push_back(m_eventList->itemIndex(*it)); ++it; } } } // Ok, recreate list // m_eventList->clear(); m_config->setGroup(EventViewConfigGroup); int timeMode = m_config->readNumEntry("timemode", 0); for (unsigned int i = 0; i < m_segments.size(); i++) { SegmentPerformanceHelper helper(*m_segments[i]); for (Segment::iterator it = m_segments[i]->begin(); m_segments[i]->isBeforeEndMarker(it); it++) { timeT eventTime = helper.getSoundingAbsoluteTime(it); QString velyStr; QString pitchStr; QString data1Str = ""; QString data2Str = ""; QString durationStr; // Event filters // if ((*it)->isa(Note::EventRestType)) { if (!(m_eventFilter & Rest)) continue; } else if ((*it)->isa(Note::EventType)) { if (!(m_eventFilter & Note)) continue; } else if ((*it)->isa(Indication::EventType)) { if (!(m_eventFilter & Indication)) continue; } else if ((*it)->isa(PitchBend::EventType)) { if (!(m_eventFilter & PitchBend)) continue; } else if ((*it)->isa(SystemExclusive::EventType)) { if (!(m_eventFilter & SystemExclusive)) continue; } else if ((*it)->isa(ProgramChange::EventType)) { if (!(m_eventFilter & ProgramChange)) continue; } else if ((*it)->isa(ChannelPressure::EventType)) { if (!(m_eventFilter & ChannelPressure)) continue; } else if ((*it)->isa(KeyPressure::EventType)) { if (!(m_eventFilter & KeyPressure)) continue; } else if ((*it)->isa(Controller::EventType)) { if (!(m_eventFilter & Controller)) continue; } else if ((*it)->isa(Text::EventType)) { if (!(m_eventFilter & Text)) continue; } else { if (!(m_eventFilter & Other)) continue; } // avoid debug stuff going to stderr if no properties found if ((*it)->has(BaseProperties::PITCH)) { int p = (*it)->get <Int>(BaseProperties::PITCH); pitchStr = QString("%1 %2 ") .arg(p).arg(MidiPitchLabel(p).getQString()); } else if ((*it)->isa(Note::EventType)) { pitchStr = "<not set>"; } if ((*it)->has(BaseProperties::VELOCITY)) { velyStr = QString("%1 "). arg((*it)->get <Int>(BaseProperties::VELOCITY)); } else if ((*it)->isa(Note::EventType)) { velyStr = "<not set>"; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -