amuse/Editor/SampleEditor.hpp

115 lines
3.3 KiB
C++
Raw Normal View History

2018-10-07 03:40:25 +00:00
#pragma once
#include "EditorWidget.hpp"
2018-07-30 06:20:03 +00:00
#include "ProjectModel.hpp"
2018-07-31 08:04:43 +00:00
#include <QScrollArea>
#include <QSlider>
#include <QCheckBox>
#include <QSpinBox>
class SampleEditor;
2018-07-30 06:20:03 +00:00
class SampleView : public QWidget
{
Q_OBJECT
2018-08-03 03:45:48 +00:00
friend class SampleControls;
2018-07-31 08:04:43 +00:00
qreal m_baseSamplesPerPx = 100.0;
2018-07-30 06:20:03 +00:00
qreal m_samplesPerPx = 100.0;
2018-07-31 08:04:43 +00:00
qreal m_zoomFactor = 1.0;
2018-07-30 06:20:03 +00:00
amuse::ObjToken<ProjectModel::SampleNode> m_node;
amuse::ObjToken<amuse::SampleEntryData> m_sample;
2018-07-31 08:04:43 +00:00
amuse::ObjToken<amuse::SoundMacro> m_playbackMacro;
2018-07-30 06:20:03 +00:00
const unsigned char* m_sampleData = nullptr;
qreal m_curSamplePos = 0.0;
int16_t m_prev1 = 0;
int16_t m_prev2 = 0;
2018-07-31 08:04:43 +00:00
QFont m_rulerFont;
int m_displaySamplePos = -1;
enum class DragState
{
None,
Start,
End
};
DragState m_dragState = DragState::None;
2018-07-30 06:20:03 +00:00
void seekToSample(qreal sample);
std::pair<std::pair<qreal, qreal>, std::pair<qreal, qreal>> iterateSampleInterval(qreal interval);
2018-07-31 08:04:43 +00:00
void calculateSamplesPerPx();
SampleEditor* getEditor() const;
2018-07-30 06:20:03 +00:00
public:
explicit SampleView(QWidget* parent = Q_NULLPTR);
2018-08-03 03:45:48 +00:00
bool loadData(ProjectModel::SampleNode* node);
2018-07-30 06:20:03 +00:00
void unloadData();
ProjectModel::INode* currentNode() const;
2018-07-31 08:04:43 +00:00
amuse::SampleEntryData* entryData() const;
const amuse::SoundMacro* soundMacro() const;
void setSamplePos(int pos);
2018-08-01 00:49:05 +00:00
void updateSampleRange(int oldSamp, int newSamp);
2018-07-30 06:20:03 +00:00
void paintEvent(QPaintEvent* ev);
2018-07-31 08:04:43 +00:00
void resetZoom();
void setZoom(int zVal);
void showEvent(QShowEvent* ev);
2018-07-30 06:20:03 +00:00
void mousePressEvent(QMouseEvent* ev);
void mouseReleaseEvent(QMouseEvent* ev);
void mouseMoveEvent(QMouseEvent* ev);
2018-07-31 08:04:43 +00:00
void wheelEvent(QWheelEvent* ev);
};
class SampleControls : public QFrame
{
Q_OBJECT
QString m_path;
QSlider* m_zoomSlider;
QCheckBox* m_loopCheck;
QSpinBox* m_loopStart;
QSpinBox* m_loopEnd;
QSpinBox* m_basePitch;
QPushButton* m_makeOtherVersion;
QMetaObject::Connection m_makeOtherConn;
QPushButton* m_showInBrowser;
2018-08-03 03:45:48 +00:00
bool m_enableUpdate = true;
bool m_enableFileWrite = true;
2018-07-31 08:04:43 +00:00
public:
2018-08-04 02:07:34 +00:00
explicit SampleControls(QWidget* parent = Q_NULLPTR);
2018-08-03 03:45:48 +00:00
void doFileWrite();
void setFileWrite(bool w);
2018-08-04 02:07:34 +00:00
void updateFileState();
void setLoopStartSample(int sample) { m_loopStart->setValue(sample); }
void setLoopEndSample(int sample) { m_loopEnd->setValue(sample); }
void loadData(bool reset);
void unloadData();
2018-07-31 08:04:43 +00:00
public slots:
void zoomSliderChanged(int val);
void loopStateChanged(int state);
void startValueChanged(int val);
void endValueChanged(int val);
void pitchValueChanged(int val);
void makeWAVVersion();
void makeCompressedVersion();
void showInBrowser();
2018-07-30 06:20:03 +00:00
};
class SampleEditor : public EditorWidget
{
Q_OBJECT
2018-07-31 08:04:43 +00:00
friend class SampleView;
friend class SampleControls;
2018-08-03 03:45:48 +00:00
friend class SampLoopUndoCommand;
friend class SampPitchUndoCommand;
2018-07-31 08:04:43 +00:00
QScrollArea* m_scrollArea;
2018-07-30 06:20:03 +00:00
SampleView* m_sampleView;
2018-07-31 08:04:43 +00:00
SampleControls* m_controls;
public:
explicit SampleEditor(QWidget* parent = Q_NULLPTR);
2018-07-29 03:37:06 +00:00
bool loadData(ProjectModel::SampleNode* node);
2018-07-30 06:20:03 +00:00
void unloadData();
ProjectModel::INode* currentNode() const;
2018-07-31 08:04:43 +00:00
const amuse::SoundMacro* soundMacro() const;
void setSamplePos(int pos);
void resizeEvent(QResizeEvent* ev);
};