audio clip editor: basics of line dragging

This commit is contained in:
Paul Davis 2021-12-10 11:59:19 -07:00
parent eac0f28642
commit 5b4dd8dcf4
2 changed files with 88 additions and 0 deletions

View File

@ -60,6 +60,7 @@ using std::max;
AudioClipEditor::AudioClipEditor ()
: spp (0)
, _current_drag (0)
{
const double scale = UIConfiguration::instance().get_ui_scale();
@ -83,6 +84,10 @@ AudioClipEditor::AudioClipEditor ()
loop_line->set (Duple (50, 0), Duple (50, 1));
loop_line->set_outline_width (line_width * scale);
start_line->Event.connect (sigc::bind (sigc::mem_fun (*this, &AudioClipEditor::line_event_handler), start_line));
end_line->Event.connect (sigc::bind (sigc::mem_fun (*this, &AudioClipEditor::line_event_handler), end_line));
loop_line->Event.connect (sigc::bind (sigc::mem_fun (*this, &AudioClipEditor::line_event_handler), loop_line));
/* hide lines until there is a region */
line_container->hide ();
@ -95,6 +100,66 @@ AudioClipEditor::~AudioClipEditor ()
drop_waves ();
}
bool
AudioClipEditor::line_event_handler (GdkEvent* ev, ArdourCanvas::Line* l)
{
std::cerr << "event type " << Gtkmm2ext::event_type_string (ev->type) << " on line " << std::endl;
switch (ev->type) {
case GDK_BUTTON_PRESS:
_current_drag = new LineDrag (*this, *l);
return true;
case GDK_BUTTON_RELEASE:
if (_current_drag) {
_current_drag->end (&ev->button);
delete _current_drag;
_current_drag = 0;
return true;
}
break;
case GDK_MOTION_NOTIFY:
if (_current_drag) {
_current_drag->motion (&ev->motion);
return true;
}
break;
default:
break;
}
return false;
}
AudioClipEditor::LineDrag::LineDrag (AudioClipEditor& ed, ArdourCanvas::Line& l)
: editor (ed)
, line (l)
{
line.grab();
}
void
AudioClipEditor::LineDrag::begin (GdkEventButton* ev)
{
}
void
AudioClipEditor::LineDrag::end (GdkEventButton* ev)
{
line.ungrab();
std::cerr << "grab end\n";
}
void
AudioClipEditor::LineDrag::motion (GdkEventMotion* ev)
{
line.set_x0 (ev->x);
line.set_x1 (ev->x);
std::cerr << "move to " << ev->x << ", " << ev->y << std::endl;
}
void
AudioClipEditor::set_colors ()
{

View File

@ -81,12 +81,35 @@ class AudioClipEditor : public ArdourCanvas::GtkCanvas
std::vector<ArdourWaveView::WaveView *> waves;
double spp;
enum LineType {
StartLine,
EndLine,
LoopLine,
};
bool event_handler (GdkEvent* ev);
bool line_event_handler (GdkEvent* ev, ArdourCanvas::Line*);
void drop_waves ();
void set_wave_heights (int);
void set_wave_spp (ARDOUR::samplecnt_t);
void set_waveform_colors ();
void set_colors ();
class LineDrag {
public:
LineDrag (AudioClipEditor&, ArdourCanvas::Line&);
void begin (GdkEventButton*);
void end (GdkEventButton*);
void motion (GdkEventMotion*);
private:
AudioClipEditor& editor;
ArdourCanvas::Line& line;
};
friend class LineDrag;
LineDrag* _current_drag;
};
class AudioClipEditorBox : public ClipEditorBox