Skip to content

Commit

Permalink
Add seq view horizontal wheel event
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jun 11, 2024
1 parent 6ffbecd commit 133f0cd
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ui/component/sequencer/SeqTimeRuler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SeqTimeRuler final
void mouseUp(const juce::MouseEvent& event) override;
void mouseMove(const juce::MouseEvent& event) override;
void mouseWheelMove(const juce::MouseEvent& event,
const juce::MouseWheelDetails& wheel);
const juce::MouseWheelDetails& wheel) override;

/** Place, IsBar, barId */
using LineItem = std::tuple<double, bool, int>;
Expand Down
5 changes: 4 additions & 1 deletion src/ui/component/sequencer/SeqTrackComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

SeqTrackComponent::SeqTrackComponent(
const ScrollFunc& scrollFunc,
const WheelFunc& wheelHFunc,
const WheelAltFunc& wheelAltHFunc,
const DragStartFunc& dragStartFunc,
const DragProcessFunc& dragProcessFunc,
const DragEndFunc& dragEndFunc) {
Expand Down Expand Up @@ -108,7 +110,8 @@ SeqTrackComponent::SeqTrackComponent(

/** Content */
this->content = std::make_unique<SeqTrackContentViewer>(
scrollFunc, dragStartFunc, dragProcessFunc, dragEndFunc);
scrollFunc, wheelHFunc, wheelAltHFunc,
dragStartFunc, dragProcessFunc, dragEndFunc);
this->addAndMakeVisible(this->content.get());
}

Expand Down
4 changes: 4 additions & 0 deletions src/ui/component/sequencer/SeqTrackComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ class SeqTrackComponent final
public juce::SettableTooltipClient {
public:
using ScrollFunc = std::function<void(double)>;
using WheelFunc = std::function<void(float, bool)>;
using WheelAltFunc = std::function<void(double, double, float, bool)>;
using DragStartFunc = std::function<void(void)>;
using DragProcessFunc = std::function<void(int, int, bool, bool)>;
using DragEndFunc = std::function<void(void)>;
SeqTrackComponent(const ScrollFunc& scrollFunc,
const WheelFunc& wheelHFunc,
const WheelAltFunc& wheelAltHFunc,
const DragStartFunc& dragStartFunc,
const DragProcessFunc& dragProcessFunc,
const DragEndFunc& dragEndFunc);
Expand Down
18 changes: 17 additions & 1 deletion src/ui/component/sequencer/SeqTrackContentViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ void DataImageUpdateTimer::timerCallback() {

SeqTrackContentViewer::SeqTrackContentViewer(
const ScrollFunc& scrollFunc,
const WheelFunc& wheelFunc,
const WheelAltFunc& wheelAltFunc,
const DragStartFunc& dragStartFunc,
const DragProcessFunc& dragProcessFunc,
const DragEndFunc& dragEndFunc)
: scrollFunc(scrollFunc),
: scrollFunc(scrollFunc), wheelFunc(wheelFunc), wheelAltFunc(wheelAltFunc),
dragStartFunc(dragStartFunc), dragProcessFunc(dragProcessFunc),
dragEndFunc(dragEndFunc) {
/** Look And Feel */
Expand Down Expand Up @@ -639,6 +641,7 @@ void SeqTrackContentViewer::mouseUp(const juce::MouseEvent& event) {
if (event.mods.isLeftButtonDown()) {
/** Move View */
if (this->viewMoving) {
this->viewMoving = false;
this->dragEndFunc();
}

Expand Down Expand Up @@ -716,6 +719,19 @@ void SeqTrackContentViewer::mouseExit(const juce::MouseEvent& event) {
this->repaint();
}

void SeqTrackContentViewer::mouseWheelMove(const juce::MouseEvent& event,
const juce::MouseWheelDetails& wheel) {
if (event.mods.isAltDown()) {
double thumbPer = event.position.getX() / (double)this->getWidth();
double centerNum = this->secStart + (this->secEnd - this->secStart) * thumbPer;

this->wheelAltFunc(centerNum, thumbPer, wheel.deltaY, wheel.isReversed);
}
else {
this->wheelFunc(wheel.deltaY, wheel.isReversed);
}
}

void SeqTrackContentViewer::updateBlockInternal(int blockIndex) {
if (auto temp = this->blockTemp[blockIndex]) {
std::tie(temp->startTime, temp->endTime, temp->offset)
Expand Down
8 changes: 8 additions & 0 deletions src/ui/component/sequencer/SeqTrackContentViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
class SeqTrackContentViewer final : public juce::Component {
public:
using ScrollFunc = std::function<void(double)>;
using WheelFunc = std::function<void(float, bool)>;
using WheelAltFunc = std::function<void(double, double, float, bool)>;
using DragStartFunc = std::function<void(void)>;
using DragProcessFunc = std::function<void(int, int, bool, bool)>;
using DragEndFunc = std::function<void(void)>;
SeqTrackContentViewer(const ScrollFunc& scrollFunc,
const WheelFunc& wheelFunc,
const WheelAltFunc& wheelAltFunc,
const DragStartFunc& dragStartFunc,
const DragProcessFunc& dragProcessFunc,
const DragEndFunc& dragEndFunc);
Expand All @@ -29,9 +33,13 @@ class SeqTrackContentViewer final : public juce::Component {
void mouseDown(const juce::MouseEvent& event) override;
void mouseUp(const juce::MouseEvent& event) override;
void mouseExit(const juce::MouseEvent& event) override;
void mouseWheelMove(const juce::MouseEvent& event,
const juce::MouseWheelDetails& wheel) override;

private:
const ScrollFunc scrollFunc;
const WheelFunc wheelFunc;
const WheelAltFunc wheelAltFunc;
const DragStartFunc dragStartFunc;
const DragProcessFunc dragProcessFunc;
const DragEndFunc dragEndFunc;
Expand Down
186 changes: 180 additions & 6 deletions src/ui/component/sequencer/SeqView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@

#define SEQ_TAIL_SEC 10;

SeqView::TrackList::TrackList(
const ScrollFunc& scrollFunc,
const WheelFunc& wheelHFunc,
const WheelAltFunc& wheelAltHFunc,
const DragStartFunc& dragStartFunc,
const DragProcessFunc& dragProcessFunc,
const DragEndFunc& dragEndFunc)
: scrollFunc(scrollFunc), wheelHFunc(wheelHFunc), wheelAltHFunc(wheelAltHFunc),
dragStartFunc(dragStartFunc), dragProcessFunc(dragProcessFunc), dragEndFunc(dragEndFunc) {}

int SeqView::TrackList::size() const {
return this->list.size();
}
Expand Down Expand Up @@ -80,6 +90,18 @@ void SeqView::TrackList::updateData(int index) {
}

void SeqView::TrackList::updateHPos(double pos, double itemSize) {
/** Size */
auto screenSize = utils::getScreenSize(this);
int headWidth = screenSize.getWidth() * 0.1;

/** Temp */
this->pos = pos;
this->itemSize = itemSize;

this->secStart = pos / itemSize;
this->secEnd = this->secStart + ((this->getWidth() - headWidth) / itemSize);

/** Tracks */
for (auto i : this->list) {
i->updateHPos(pos, itemSize);
}
Expand All @@ -94,12 +116,117 @@ void SeqView::TrackList::updateVPos(double pos, double itemSize) {
}
}

void SeqView::TrackList::mouseDown(const juce::MouseEvent& event) {
/** Size */
auto screenSize = utils::getScreenSize(this);
int headWidth = screenSize.getWidth() * 0.1;

/** Get Tool Type */
auto tool = Tools::getInstance()->getType();

/** Not Head */
if (event.position.x > headWidth) {
if (event.mods.isLeftButtonDown()) {
/** Check Tool Type */
switch (tool) {
case Tools::Type::Hand:
/** Move View Area */
this->viewMoving = true;
this->dragStartFunc();
break;
}
}
}
}

void SeqView::TrackList::mouseUp(const juce::MouseEvent& event) {
if (event.mods.isRightButtonDown()) {
this->add();
if (event.mods.isLeftButtonDown()) {
/** Move View */
if (this->viewMoving) {
this->viewMoving = false;
this->dragEndFunc();
}
}
else if (event.mods.isRightButtonDown()) {
if (!event.mouseWasDraggedSinceMouseDown()) {
this->add();
}
}
}

void SeqView::TrackList::mouseMove(const juce::MouseEvent& event) {
/** Size */
auto screenSize = utils::getScreenSize(this);
int headWidth = screenSize.getWidth() * 0.1;

float posX = event.position.getX();

/** Not Head */
if (posX > headWidth) {
/** Move */
if (Tools::getInstance()->getType() == Tools::Type::Hand) {
this->setMouseCursor(juce::MouseCursor::DraggingHandCursor);
return;
}
}

this->setMouseCursor(juce::MouseCursor::NormalCursor);
}

void SeqView::TrackList::mouseDrag(const juce::MouseEvent& event) {
/** Size */
auto screenSize = utils::getScreenSize(this);
int headWidth = screenSize.getWidth() * 0.1;

/** Not Head */
if (event.mouseDownPosition.getX() > headWidth) {
/** Auto Scroll */
float xPos = event.position.getX();
if (!this->viewMoving) {
double delta = 0;
if (xPos > this->getWidth()) {
delta = xPos - this->getWidth();
}
else if (xPos < headWidth) {
delta = xPos - headWidth;
}

if (delta != 0) {
this->scrollFunc(delta / 4);
}
}

if (event.mods.isLeftButtonDown()) {
/** Move View */
if (this->viewMoving) {
int distanceX = event.getDistanceFromDragStartX();
int distanceY = event.getDistanceFromDragStartY();
this->dragProcessFunc(distanceX, distanceY, true, true);
}
}
}
}

void SeqView::TrackList::mouseWheelMove(const juce::MouseEvent& event,
const juce::MouseWheelDetails& wheel) {
/** Size */
auto screenSize = utils::getScreenSize(this);
int headWidth = screenSize.getWidth() * 0.1;

if (event.position.getX() > headWidth) {
if (event.mods.isAltDown()) {
double thumbPer = (event.position.getX() - headWidth) / (double)(this->getWidth() - headWidth);
double centerNum = this->secStart + (this->secEnd - this->secStart) * thumbPer;

this->wheelAltHFunc(centerNum, thumbPer, wheel.deltaY, wheel.isReversed);
}
else {
this->wheelHFunc(wheel.deltaY, wheel.isReversed);
}
}

}

void SeqView::TrackList::add() {
CoreActions::insertSeqGUI();
}
Expand All @@ -116,10 +243,6 @@ SeqView::SeqView()
this->adsorbIcon->replaceColour(juce::Colours::black,
this->getLookAndFeel().findColour(juce::TextButton::ColourIds::textColourOffId));

/** Track List */
this->trackList = std::make_unique<TrackList>();
this->addAndMakeVisible(this->trackList.get());

/** Scroller */
this->hScroller = std::make_unique<Scroller>(false,
[this] { return (double)(this->getViewWidth()); },
Expand All @@ -142,6 +265,45 @@ SeqView::SeqView()
this->paintTrackPreview(g, itemIndex, width, height, vertical); });
this->addAndMakeVisible(this->vScroller.get());

/** Track List */
this->trackList = std::make_unique<TrackList>(
[comp = ScrollerBase::SafePointer(this->hScroller.get())]
(double delta) {
if (comp) {
comp->scroll(delta);
}
},
[comp = ScrollerBase::SafePointer(this->hScroller.get())]
(float deltaY, bool reversed) {
if (comp) {
comp->mouseWheelOutside(deltaY, reversed);
}
},
[comp = ScrollerBase::SafePointer(this->hScroller.get())]
(double centerNum, double thumbPer, float deltaY, bool reversed) {
if (comp) {
comp->mouseWheelOutsideWithAlt(centerNum, thumbPer, deltaY, reversed);
}
},
[comp = ScrollerBase::SafePointer(this)] {
if (comp) {
comp->processAreaDragStart();
}
},
[comp = ScrollerBase::SafePointer(this)]
(int distanceX, int distanceY, bool moveX, bool moveY) {
if (comp) {
comp->processAreaDragTo(
distanceX, distanceY, moveX, moveY);
}
},
[comp = ScrollerBase::SafePointer(this)] {
if (comp) {
comp->processAreaDragEnd();
}
});
this->addAndMakeVisible(this->trackList.get());

/** Button */
this->adsorbButton = std::make_unique<juce::DrawableButton>(
TRANS("Adsorb"), juce::DrawableButton::ButtonStyle::ImageOnButtonBackground);
Expand Down Expand Up @@ -479,6 +641,18 @@ void SeqView::update(int index) {
comp->scroll(delta);
}
},
[comp = ScrollerBase::SafePointer(this->hScroller.get())]
(float deltaY, bool reversed) {
if (comp) {
comp->mouseWheelOutside(deltaY, reversed);
}
},
[comp = ScrollerBase::SafePointer(this->hScroller.get())]
(double centerNum, double thumbPer, float deltaY, bool reversed) {
if (comp) {
comp->mouseWheelOutsideWithAlt(centerNum, thumbPer, deltaY, reversed);
}
},
[comp = ScrollerBase::SafePointer(this)] {
if (comp) {
comp->processAreaDragStart();
Expand Down
30 changes: 29 additions & 1 deletion src/ui/component/sequencer/SeqView.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ class SeqView final

class TrackList : public juce::Component {
public:
TrackList() = default;
using ScrollFunc = std::function<void(double)>;
using WheelFunc = std::function<void(float, bool)>;
using WheelAltFunc = std::function<void(double, double, float, bool)>;
using DragStartFunc = std::function<void(void)>;
using DragProcessFunc = std::function<void(int, int, bool, bool)>;
using DragEndFunc = std::function<void(void)>;
TrackList(const ScrollFunc& scrollFunc,
const WheelFunc& wheelHFunc,
const WheelAltFunc& wheelAltHFunc,
const DragStartFunc& dragStartFunc,
const DragProcessFunc& dragProcessFunc,
const DragEndFunc& dragEndFunc);

int size() const;
void remove(int index);
Expand All @@ -55,11 +66,28 @@ class SeqView final
void updateHPos(double pos, double itemSize);
void updateVPos(double pos, double itemSize);

void mouseDown(const juce::MouseEvent& event) override;
void mouseUp(const juce::MouseEvent& event) override;
void mouseMove(const juce::MouseEvent& event) override;
void mouseDrag(const juce::MouseEvent& event) override;
void mouseWheelMove(const juce::MouseEvent& event,
const juce::MouseWheelDetails& wheel) override;

private:
juce::OwnedArray<SeqTrackComponent> list;

const ScrollFunc scrollFunc;
const WheelFunc wheelHFunc;
const WheelAltFunc wheelAltHFunc;
const DragStartFunc dragStartFunc;
const DragProcessFunc dragProcessFunc;
const DragEndFunc dragEndFunc;

double pos = 0, itemSize = 0;
double secStart = 0, secEnd = 0;

bool viewMoving = false;

void add();

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TrackList)
Expand Down

0 comments on commit 133f0cd

Please sign in to comment.