Timeline: Add option to import source at mouse via timeline context menu (as an alternative to DND)
Closes #211.
This commit is contained in:
parent
1daf0f6150
commit
10c31e5729
|
@ -253,24 +253,17 @@ Audio_Sequence::draw ( void )
|
||||||
fl_pop_clip();
|
fl_pop_clip();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** event handler that supports DND of audio clips */
|
|
||||||
int
|
int
|
||||||
Audio_Sequence::handle ( int m )
|
Audio_Sequence::handle_paste ( const char *text )
|
||||||
{
|
{
|
||||||
switch ( m )
|
int X = Fl::event_x();
|
||||||
{
|
|
||||||
case FL_PASTE:
|
|
||||||
{
|
|
||||||
if ( ! Fl::event_inside( this ) )
|
|
||||||
return 0;
|
|
||||||
const char *text = Fl::event_text();
|
|
||||||
|
|
||||||
if ( ! strcmp( text, "Audio_Region" ) )
|
if ( ! strcmp( text, "Audio_Region" ) )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
char *file;
|
char *file;
|
||||||
|
|
||||||
if ( ! sscanf( text, "file://%a[^\r\n]\n", &file ) )
|
if ( ! sscanf( text, "file://%m[^\r\n]\n", &file ) )
|
||||||
{
|
{
|
||||||
WARNING( "invalid drop \"%s\"\n", text );
|
WARNING( "invalid drop \"%s\"\n", text );
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -339,13 +332,33 @@ Audio_Sequence::handle ( int m )
|
||||||
free( file );
|
free( file );
|
||||||
|
|
||||||
Audio_Region *r =
|
Audio_Region *r =
|
||||||
new Audio_Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - drawable_x() ) );
|
new Audio_Region( c, this, timeline->xoffset + timeline->x_to_ts( X - drawable_x() ) );
|
||||||
|
|
||||||
r->log_create();
|
r->log_create();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** event handler that supports DND of audio clips */
|
||||||
|
int
|
||||||
|
Audio_Sequence::handle ( int m )
|
||||||
|
{
|
||||||
|
switch ( m )
|
||||||
|
{
|
||||||
|
case FL_PASTE:
|
||||||
|
{
|
||||||
|
DMESSAGE("Got sequence paste");
|
||||||
|
|
||||||
|
if ( ! Fl::event_inside( this ) )
|
||||||
|
{
|
||||||
|
DMESSAGE("ignoring");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle_paste(Fl::event_text());
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return Sequence::handle( m );
|
return Sequence::handle( m );
|
||||||
|
|
|
@ -51,6 +51,8 @@ protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
int handle_paste ( const char *text );
|
||||||
|
|
||||||
int handle ( int m );
|
int handle ( int m );
|
||||||
|
|
||||||
LOG_CREATE_FUNC( Audio_Sequence );
|
LOG_CREATE_FUNC( Audio_Sequence );
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <FL/Fl_Menu_Button.H>
|
#include <FL/Fl_Menu_Button.H>
|
||||||
#include <FL/Fl_Panzoomer.H>
|
#include <FL/Fl_Panzoomer.H>
|
||||||
#include <FL/Fl_Tile.H>
|
#include <FL/Fl_Tile.H>
|
||||||
|
#include <FL/Fl_File_Chooser.H>
|
||||||
|
|
||||||
#include "Timeline.H"
|
#include "Timeline.H"
|
||||||
#include "Tempo_Sequence.H"
|
#include "Tempo_Sequence.H"
|
||||||
|
@ -373,6 +374,9 @@ Timeline::add_take_for_armed_tracks ( void )
|
||||||
track_lock.unlock();
|
track_lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* coordinates of mouse at time context menu is brought up. */
|
||||||
|
static int menu_event_x = 0;
|
||||||
|
static int menu_event_y = 0;
|
||||||
void
|
void
|
||||||
Timeline::menu_cb ( Fl_Menu_ *m )
|
Timeline::menu_cb ( Fl_Menu_ *m )
|
||||||
{
|
{
|
||||||
|
@ -570,6 +574,31 @@ Timeline::menu_cb ( Fl_Menu_ *m )
|
||||||
{
|
{
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
else if ( ! strcmp( picked, "Import source at mouse" ) )
|
||||||
|
{
|
||||||
|
Fl::e_x = menu_event_x;
|
||||||
|
Fl::e_y = menu_event_y;
|
||||||
|
|
||||||
|
Track *t = Timeline::event_inside();
|
||||||
|
|
||||||
|
if ( t )
|
||||||
|
{
|
||||||
|
const char *name = fl_file_chooser( "Import source", "*", NULL );
|
||||||
|
|
||||||
|
if ( name )
|
||||||
|
{
|
||||||
|
char *url;
|
||||||
|
asprintf( &url, "file:///%s\n", name );
|
||||||
|
|
||||||
|
Fl::e_x = menu_event_x;
|
||||||
|
Fl::e_y = menu_event_y;
|
||||||
|
|
||||||
|
t->sequence()->handle_paste(url);
|
||||||
|
|
||||||
|
free(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
WARNING( "programming error: Unknown menu item" );
|
WARNING( "programming error: Unknown menu item" );
|
||||||
}
|
}
|
||||||
|
@ -630,6 +659,7 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : BASE( X, Y, W
|
||||||
menu->add( "Edit end to playhead", FL_CTRL + ']', 0, 0 );
|
menu->add( "Edit end to playhead", FL_CTRL + ']', 0, 0 );
|
||||||
menu->add( "Punch from edit", FL_CTRL + FL_SHIFT + 'p', 0, 0 );
|
menu->add( "Punch from edit", FL_CTRL + FL_SHIFT + 'p', 0, 0 );
|
||||||
menu->add( "Playback from edit", FL_CTRL + FL_SHIFT + 'l', 0, 0 );
|
menu->add( "Playback from edit", FL_CTRL + FL_SHIFT + 'l', 0, 0 );
|
||||||
|
menu->add( "Import source at mouse", 0, 0, 0 );
|
||||||
menu->add( "Redraw", FL_CTRL + 'l', 0, 0 );
|
menu->add( "Redraw", FL_CTRL + 'l', 0, 0 );
|
||||||
|
|
||||||
menu_set_callback( const_cast<Fl_Menu_Item*>(menu->menu()), &Timeline::menu_cb, (void*)this );
|
menu_set_callback( const_cast<Fl_Menu_Item*>(menu->menu()), &Timeline::menu_cb, (void*)this );
|
||||||
|
@ -1730,6 +1760,20 @@ Timeline::handle ( int m )
|
||||||
}
|
}
|
||||||
else if ( test_press( FL_BUTTON3 ) )
|
else if ( test_press( FL_BUTTON3 ) )
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
menu_event_x = X;
|
||||||
|
menu_event_y = Y;
|
||||||
|
|
||||||
|
Track *t = Timeline::event_inside();
|
||||||
|
|
||||||
|
Fl_Menu_Item *mi = (Fl_Menu_Item*)menu->find_item("Import source at mouse");
|
||||||
|
|
||||||
|
if ( t )
|
||||||
|
mi->activate();
|
||||||
|
else
|
||||||
|
mi->deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
menu_popup( menu );
|
menu_popup( menu );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1789,7 +1833,7 @@ Timeline::handle ( int m )
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** retrun a pointer to the track named /name/, or NULL if no track is named /name/ */
|
/** retrun a pointer to the track named /name/, or NULL if no track is named /name/ */
|
||||||
|
|
Loading…
Reference in New Issue