1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/* TIATracker, (c) 2016 Andre "Kylearan" Wichmann.
* Website: https://bitbucket.org/kylearan/tiatracker
* Email: andre.wichmann@gmx.de
* See the file "license.txt" for information on usage and redistribution
* of this file.
*/
#ifndef PATTERNEDITOR_H
#define PATTERNEDITOR_H
#include <QObject>
#include <QWidget>
#include "track/track.h"
#include <QFontDatabase>
#include "tiasound/pitchguide.h"
#include <QMenu>
#include "instrumentselector.h"
#include "emulation/player.h"
class PatternEditor : public QWidget
{
Q_OBJECT
public:
explicit PatternEditor(QWidget *parent = 0);
void registerTrack(Track::Track *newTrack);
void registerPitchGuide(TiaSound::PitchGuide *newGuide);
void registerPlayer(Emulation::Player *newPlayer);
void registerMuteAction(QAction *newAction);
void registerPatternMenu(QMenu *newPatternMenu);
void registerChannelMenu(QMenu *newChannelMenu);
void registerInstrumentSelector(InstrumentSelector *selector);
int getEditPos();
int getSelectedChannel();
QString constructRowString(int curPatternNoteIndex, Track::Pattern *curPattern);
QSize sizeHint() const;
signals:
void editPosChanged(int newPos);
void channelContextEvent(int channel, int row);
void editChannelChanged(int newChannel);
public slots:
// Global actions
void moveUp(bool);
void moveDown(bool);
void moveLeft(bool);
void moveRight(bool);
void switchChannel(bool);
void gotoFirstRow(bool);
void gotoLastRow(bool);
void gotoNextPattern(bool);
void gotoPreviousPattern(bool);
void setEditPos(int newPos);
void setEditPos(int newChannel, int newPos);
void validateEditPos();
void advanceEditPos();
void setRowsPerBeat(int value);
void setRowToInstrument(int frequency);
void newPlayerPos(int pos1, int pos2);
// Slot for QCheckBox "follow"
void toggleFollow_clicked(bool toggle);
void toggleLoop_clicked(bool toggle);
protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
private:
static const int noteFontSize = 12;
static const int legendFontSize = 12;
static const int noteMargin = 6;
static const int patternNameWidth = 120;
static const int patternNameMargin = 4;
static const int minHeight = 400;
void drawPatternNameAndSeparator(int yPos, int nameXPos, int curPatternNoteIndex, int channel, int xPos, int curEntryIndex, QPainter *painter, Track::Pattern *curPattern);
void drawGoto(int channel, int yPos, Track::Pattern *curPattern, Track::SequenceEntry *curEntry, QPainter *painter, int nameXPos, int curPatternNoteIndex);
void drawTimestamp(int row, QPainter *painter, int yPos, int channel);
void paintChannel(QPainter *painter, int channel, int xPos, int nameXPos);
/* If x and y are in a valid row with regards to the channel clicked,
* the channel number, row and note index get written to the parameters
* and true is returned.
*/
bool clickedInValidRow(int x, int y, int *channel, int *noteIndex);
int calcChannelRowPos(int yPos);
int numRows; // number of visible rows
int topMargin; // margin before first row is displayed
int noteFontHeight;
int noteAreaWidth;
int timeAreaWidth;
int widgetWidth;
QFont noteFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
QFont legendFont{"Helvetica"};
int legendFontHeight;
int timelineWidth;
Track::Track *pTrack;
TiaSound::PitchGuide *pPitchGuide;
Emulation::Player *pPlayer = nullptr;
QAction *muteAction = nullptr;
QMenu *pPatternMenu = nullptr;
QMenu *pChannelMenu = nullptr;
InstrumentSelector *pInsSelector = nullptr;
int selectedChannel = 0;
// Current editor note focus, i.e. middle-of-screen highlight
int editPos = 0;
bool follow = false;
bool loop = false;
};
#endif // PATTERNEDITOR_H
|