|
| 1 | +#include "pianorollcontainer.h" |
| 2 | +#include "src/mainwindow.h" |
| 3 | +#include "src/pianorollwidget.h" |
| 4 | +#include "src/keyboard.h" |
| 5 | +#include "src/velocityview.h" |
| 6 | +#include "src/tracklengthview.h" |
| 7 | +#include "src/trackmidi.h" |
| 8 | + |
| 9 | +/*This class represents a collection of widgets whose uses are all linked to |
| 10 | + * one another. A Piano roll for editing MIDI, a Keyboard to for simple user |
| 11 | + * playback, and a Velocity view for editing velocities. |
| 12 | + * |
| 13 | + * */ |
| 14 | + |
| 15 | +PianoRollContainer::PianoRollContainer() |
| 16 | +{ |
| 17 | + mainLayout = new QVBoxLayout; |
| 18 | + hLayout = new QHBoxLayout; |
| 19 | + _pianoRoll = new PianoRollWidget(this); |
| 20 | + _keyboard = new Keyboard(this); |
| 21 | + _velocityView = new VelocityView(this); |
| 22 | + _trackLengthView = new TrackLengthView(this); |
| 23 | + auto* hlayout2 = new QHBoxLayout; |
| 24 | + auto* hlayout3 = new QHBoxLayout; |
| 25 | + |
| 26 | + hLayout->addWidget(_keyboard); |
| 27 | + hLayout->addWidget(_pianoRoll); |
| 28 | + hlayout2->addSpacing(_keyboard->width()); |
| 29 | + hlayout2->addWidget(_velocityView); |
| 30 | + hlayout2->addSpacing(qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)); |
| 31 | + hlayout3->addSpacing(_keyboard->width()); |
| 32 | + hlayout3->addWidget(_trackLengthView); |
| 33 | + hlayout3->addSpacing(qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)); |
| 34 | + |
| 35 | + mainLayout->addLayout(hlayout3); |
| 36 | + mainLayout->addLayout(hLayout); |
| 37 | + mainLayout->addLayout(hlayout2); |
| 38 | + setLayout(mainLayout); |
| 39 | + |
| 40 | + hLayout->setSpacing(0); |
| 41 | + hLayout->setContentsMargins(0,0,0,0); |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +void PianoRollContainer::restoreTrack(TrackMidi* midiTrack) |
| 46 | +{ |
| 47 | + _currentMidiTrack = midiTrack; |
| 48 | + _pianoRoll->restoreTrack(midiTrack); |
| 49 | + _velocityView->restoreTrack(midiTrack); |
| 50 | +} |
| 51 | + |
| 52 | +void PianoRollContainer::playKeyboardNote(int note, bool active) |
| 53 | +{ |
| 54 | + auto velocity = (active ? 45 : 0); |
| 55 | + _currentMidiTrack->addMidiEventToPlayback(0x90,note,velocity,g_timer->currentValue()); |
| 56 | +} |
| 57 | + |
| 58 | +void PianoRollContainer::scaleWidgets(QMatrix matrix) |
| 59 | +{ |
| 60 | + |
| 61 | + _pianoRoll->setMatrix(matrix); |
| 62 | + _trackLengthView->setMatrix(matrix); |
| 63 | + _trackLengthView->setMatrix(matrix); |
| 64 | + auto m = _velocityView->matrix(); |
| 65 | + m.setMatrix(matrix.m11(),m.m12(),m.m21(),m.m22(),0,0); |
| 66 | + _velocityView->setMatrix(m); |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | +void PianoRollContainer::setScrollPositions(int value, Qt::Orientation axis) |
| 71 | +{ |
| 72 | + if(axis == Qt::Horizontal) |
| 73 | + { |
| 74 | + _pianoRoll->horizontalScrollBar()->setValue(value); |
| 75 | + _velocityView->horizontalScrollBar()->setValue(value); |
| 76 | + _trackLengthView->horizontalScrollBar()->setValue(value); |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + _pianoRoll->verticalScrollBar()->setValue(value); |
| 81 | + _keyboard->verticalScrollBar()->setValue(value); |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +void PianoRollContainer::setScaleFactor(qreal scale) |
| 86 | +{ |
| 87 | + pianoRoll()->scaleFactor = scale; |
| 88 | + trackLengthView()->scaleFactor = scale; |
| 89 | + trackLengthView()->viewport()->update(); |
| 90 | +} |
0 commit comments