Skip to content

Commit

Permalink
Added AudioButton.
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed Mar 25, 2024
1 parent 3faf981 commit 2c7b913
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
90 changes: 90 additions & 0 deletions mrv2/lib/mrvWidgets/mrvAudioButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// SPDX-License-Identifier: BSD-3-Clause
// mrv2
// Copyright Contributors to the mrv2 Project. All rights reserved.


#include <FL/Fl_Menu_Button.H>

#include "mrvCore/mrvI8N.h"

#include "mrvWidgets/mrvAudioButton.h"

#include "mrvFl/mrvCallbacks.h"

#include "mrvApp/mrvApp.h"

namespace mrv
{

static void change_audio_track_cb(Fl_Menu_Button* o, void* d)
{
auto audioButton = static_cast<AudioButton*>(d);
int idx = o->value();

audioButton->current_track(idx);

clone_and_replace_cb(o, d);
}

AudioButton::AudioButton(int X, int Y, int W, int H, const char* l) :
Fl_Button(X, Y, W, H, l)
{
}

int AudioButton::current_track() const
{
return currentTrack;
}

void AudioButton::current_track(int idx)
{
currentTrack = idx;
}

int AudioButton::handle(int e)
{
switch (e)
{
case FL_PUSH:
if (Fl::event_button3() && audioTracks.size() > 1)
{
Fl_Menu_Button menu(0, 0, 0, 0);
menu.type(Fl_Menu_Button::POPUP3);
menu.clear();

for (const auto& track : audioTracks)
{
menu.add(
track.c_str(), 0, (Fl_Callback*)change_audio_track_cb,
this);
}
menu.menu_end();

menu.popup();
return 1;
}
break;
}
return Fl_Button::handle(e);
}

void AudioButton::clear_tracks()
{
currentTrack = -1;
audioTracks.clear();
}

void AudioButton::add_track(const std::string& name)
{
audioTracks.push_back(name);
}

void AudioButton::add_track()
{
char buf[256];
unsigned idx = audioTracks.size() + 1;
snprintf(buf, 256, _("Track #%d"), idx);
add_track(buf);
}

} // namespace mrv
34 changes: 34 additions & 0 deletions mrv2/lib/mrvWidgets/mrvAudioButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: BSD-3-Clause
// mrv2
// Copyright Contributors to the mrv2 Project. All rights reserved.

#pragma once

#include <string>
#include <vector>

#include <FL/Fl_Button.H>

namespace mrv
{

class AudioButton : public Fl_Button
{
public:
AudioButton(int, int, int, int, const char* = 0);
virtual ~AudioButton(){};
virtual int handle(int e) override;

int current_track() const;
void current_track(int idx);

void clear_tracks();
void add_track(const std::string& name);
void add_track();

protected:
int currentTrack = -1;
std::vector<std::string> audioTracks;
};

} // namespace mrv

0 comments on commit 2c7b913

Please sign in to comment.