| 1 |
/* |
| 2 |
* Copyright (C) 2020-2023 Rerrah |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person |
| 5 |
* obtaining a copy of this software and associated documentation |
| 6 |
* files (the "Software"), to deal in the Software without |
| 7 |
* restriction, including without limitation the rights to use, |
| 8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following |
| 11 |
* conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef ADPCM_SAMPLE_EDITOR_HPP |
| 27 |
#define ADPCM_SAMPLE_EDITOR_HPP |
| 28 |
|
| 29 |
#include <memory> |
| 30 |
#include <cstdint> |
| 31 |
#include <QWidget> |
| 32 |
#include <QEvent> |
| 33 |
#include <QDragEnterEvent> |
| 34 |
#include <QDropEvent> |
| 35 |
#include <QPixmap> |
| 36 |
#include <QString> |
| 37 |
#include <QPoint> |
| 38 |
#include "bamboo_tracker.hpp" |
| 39 |
#include "configuration.hpp" |
| 40 |
#include "instrument/sample_repeat.hpp" |
| 41 |
#include "gui/color_palette.hpp" |
| 42 |
|
| 43 |
namespace Ui { |
| 44 |
class ADPCMSampleEditor; |
| 45 |
} |
| 46 |
|
| 47 |
class ADPCMSampleEditor : public QWidget |
| 48 |
{ |
| 49 |
Q_OBJECT |
| 50 |
|
| 51 |
public: |
| 52 |
explicit ADPCMSampleEditor(QWidget *parent = nullptr); |
| 53 |
~ADPCMSampleEditor() override; |
| 54 |
void setCore(std::weak_ptr<BambooTracker> core); |
| 55 |
void setConfiguration(std::weak_ptr<Configuration> config); |
| 56 |
void setColorPalette(std::shared_ptr<ColorPalette> palette); |
| 57 |
|
| 58 |
int getSampleNumber() const; |
| 59 |
|
| 60 |
void setInstrumentSampleParameters(int sampNum, bool repeatable, const SampleRepeatRange& repeatRange, |
| 61 |
int rKeyNum, int rDeltaN, size_t start, size_t stop, std::vector<uint8_t> sample); |
| 62 |
|
| 63 |
signals: |
| 64 |
void modified(); |
| 65 |
void sampleNumberChanged(int n); // NEED Direct connection |
| 66 |
void sampleParameterChanged(int wfNum); |
| 67 |
void sampleAssignRequested(); |
| 68 |
void sampleMemoryChanged(); |
| 69 |
|
| 70 |
public slots: |
| 71 |
void onSampleNumberChanged(); |
| 72 |
void onSampleMemoryUpdated(size_t start, size_t stop); |
| 73 |
void onNoteNamesUpdated(); |
| 74 |
|
| 75 |
protected: |
| 76 |
bool eventFilter(QObject* obj, QEvent* ev) override; |
| 77 |
void dragEnterEvent(QDragEnterEvent* event) override; |
| 78 |
void dropEvent(QDropEvent* event) override; |
| 79 |
|
| 80 |
private: |
| 81 |
Ui::ADPCMSampleEditor *ui; |
| 82 |
bool isIgnoreEvent_; |
| 83 |
|
| 84 |
std::weak_ptr<BambooTracker> bt_; |
| 85 |
std::weak_ptr<Configuration> config_; |
| 86 |
std::shared_ptr<ColorPalette> palette_; |
| 87 |
|
| 88 |
QPixmap memPixmap_, sampViewPixmap_; |
| 89 |
int zoom_, viewedSampLen_, gridIntr_; |
| 90 |
QPoint cursorSamp_, prevPressedSamp_; |
| 91 |
|
| 92 |
size_t addrStart_, addrStop_; |
| 93 |
std::vector<int16_t> sample_; |
| 94 |
|
| 95 |
void importSampleFrom(const QString file); |
| 96 |
void updateSampleMemoryBar(); |
| 97 |
void updateSampleView(); |
| 98 |
void updateUsersView(); |
| 99 |
|
| 100 |
void detectCursorSamplePosition(int cx, int cy); |
| 101 |
|
| 102 |
void sendEditedSample(); |
| 103 |
|
| 104 |
inline QString updateDetailView() const |
| 105 |
{ |
| 106 |
return QString("(%1, %2), %3, x%4") |
| 107 |
.arg(cursorSamp_.x()).arg(cursorSamp_.y()).arg(sample_.size()).arg(zoom_ + 1); |
| 108 |
} |
| 109 |
|
| 110 |
enum class DrawMode { Disabled, Normal, Direct }; |
| 111 |
DrawMode drawMode_; |
| 112 |
|
| 113 |
private slots: |
| 114 |
void on_sampleNumSpinBox_valueChanged(int arg1); |
| 115 |
void on_repeatCheckBox_toggled(bool checked); |
| 116 |
void on_repeatBeginSpinBox_valueChanged(int); |
| 117 |
void on_repeatEndSpinBox_valueChanged(int); |
| 118 |
void on_rootRateSpinBox_valueChanged(int arg1); |
| 119 |
void on_action_Resize_triggered(); |
| 120 |
void on_actionRe_verse_triggered(); |
| 121 |
void on_actionZoom_In_triggered(); |
| 122 |
void on_actionZoom_Out_triggered(); |
| 123 |
void on_horizontalScrollBar_valueChanged(int); |
| 124 |
void on_action_Import_triggered(); |
| 125 |
void on_action_Clear_triggered(); |
| 126 |
void on_action_Grid_View_triggered(); |
| 127 |
void on_actionG_rid_Settings_triggered(); |
| 128 |
void on_action_Draw_Sample_triggered(bool checked); |
| 129 |
void on_actionDirec_t_Draw_triggered(bool checked); |
| 130 |
}; |
| 131 |
|
| 132 |
#endif // ADPCM_SAMPLE_EDITOR_HPP |