Пример #1
0
int
Track::handle ( int m )
{

/*     if ( m != FL_NO_EVENT ) */
/*         DMESSAGE( "%s", event_name( m ) ); */
    static Fl_Widget *dragging = NULL;

    switch ( m )
    {
        case FL_DND_ENTER:
        case FL_DND_LEAVE:
        case FL_DND_DRAG:
        case FL_DND_RELEASE:
        case FL_PASTE:
            if ( Fl::event_x() > Track::width() )
                return sequence()->handle(m);
        default:
            break;
    }

    switch ( m )
    {
        case FL_KEYBOARD:
        {
            Fl_Menu_Button * men = &menu();

            if ( Fl::event_key() == FL_Menu )
            {
                menu_popup( men );
                return 1;
            }
            else
                return men->test_shortcut() || Fl_Group::handle( m );
        }
        case FL_MOUSEWHEEL:
        {
            Logger log( this );

            if ( ! Fl::event_shift() )
                return Fl_Group::handle( m );

            int d = Fl::event_dy();

            if ( d < 0 )
                size( size() - 1 );
            else
                size( size() + 1 );

            return 1;
        }
        case FL_PUSH:
        {
            if ( Fl::event_button1() && Fl::event_inside( ((Track_Header*)child(0))->color_box ) )
            {
                dragging = this;
                return 1;
            }
            if ( Fl::event_button1() && Fl::event_inside( ((Track_Header*)child(0))->output_connector_handle ) )
                return 1;
            
            Logger log( this );

            if ( Fl_Group::handle( m ) )
                return 1;

            if ( test_press( FL_BUTTON3 ) && Fl::event_x() < Track::width() )
            {
                menu_popup( &menu() );
                return 1;
            }

            return 0;
        }
        /* we have to prevent Fl_Group::handle() from getting these, otherwise it will mess up Fl::belowmouse() */
        case FL_ENTER:
        case FL_LEAVE:
        case FL_MOVE:
            if ( Fl::event_x() >= Track::width() )
            {
                return Fl_Group::handle(m);
            }
            return 1;
        case FL_DND_ENTER:
            return 1;
        case FL_DND_LEAVE:
    
            if ( ! Fl::event_inside(this) && this == receptive_to_drop )
            {
                receptive_to_drop = 0;
                redraw();
                Fl::selection_owner(0);
            }
            return 1;
        case FL_RELEASE:
            if ( dragging == this )
            {
                dragging = NULL;
                timeline->insert_track( this, timeline->event_inside() );
                return 1;
            }
            return 0;
            break;
        case FL_DND_RELEASE:
            receptive_to_drop = 0;
            redraw();
            Fl::selection_owner(0);
            return 1;
        case FL_DND_DRAG:
        {
            
            if ( receptive_to_drop == ((Track_Header*)child(0))->input_connector_handle )
                return 1;

           

            if ( Fl::event_inside( ((Track_Header*)child(0))->input_connector_handle )
                 && receptive_to_drop != ((Track_Header*)child(0))->input_connector_handle )
            
            {
                receptive_to_drop = ((Track_Header*)child(0))->input_connector_handle;
                redraw();
                return 1;
            }
            else
            {
                receptive_to_drop = NULL;
                redraw();
                return 0;
            }
        }
        case FL_PASTE:
        {
            receptive_to_drop = 0;
            redraw();

            if (! Fl::event_inside( ((Track_Header*)child(0))->input_connector_handle ) )
                return 0;

            /* NOW we get the text... */
            const char *text = Fl::event_text();

            DMESSAGE( "Got drop text \"%s\"",text);

            if ( strncmp( text, "jack.port://", strlen( "jack.port://" ) ) )
            {
                return 0;
            }
                        
            std::vector<std::string> port_names;

            char *port_name;
            int end;
            while (  sscanf( text, "jack.port://%a[^\r\n]\r\n%n", &port_name, &end ) > 0 )
            {
                DMESSAGE( "Scanning %s", port_name );
                port_names.push_back( port_name );
                free(port_name );
                
                text += end;
            }

            for ( unsigned int i = 0; i < input.size() && i < port_names.size(); i++)
            {
                const char *pn = port_names[i].c_str();
                
                JACK::Port *ji = &input[i];
                
                if ( ji->connected_to( pn ) )
                {
                    
                    DMESSAGE( "Disconnecting from \"%s\"", pn );
                    ji->disconnect( pn );
                }
                else
                {
                    DMESSAGE( "Connecting to %s", pn );
                    ji->connect( pn );
                }
            }
          
            Fl::selection_owner(0);

            return 1;
        }
        case FL_DRAG:
        {
            if ( this != Fl::selection_owner() &&
                 Fl::event_inside( ((Track_Header*)child(0))->output_connector_handle ) )
            {
                char *s = (char*)malloc(256);
                s[0] = 0;
  
                for ( unsigned int i = 0; i < output.size(); ++i )
                {
                    char *s2;
                    asprintf(&s2, "jack.port://%s:%s\r\n", instance_name, output[i].name() );
                    
                    s = (char*)realloc( s, strlen( s ) + strlen( s2 ) + 1 ); 
                    strcat( s, s2 );

                    free( s2 );
                }
               
                Fl::copy(s, strlen(s) + 1, 0);
                Fl::selection_owner(this);

                free( s );

                Fl::dnd();
        
                return 1;
            }
            else
            {
                return 1;
            }
        }
        default:
            return Fl_Group::handle( m );
    }

    return 0;
}
Пример #2
0
int
JACK_Module::handle ( int m )
{
    static unsigned long _event_state = 0;

    unsigned long evstate = Fl::event_state();

    switch ( m ) 
    {
        case FL_PUSH:
            if ( Fl::event_inside( output_connection_handle ) ||
                 Fl::event_inside( output_connection2_handle ) ||
                 Fl::event_inside( input_connection_handle ) )
            {
                _event_state = evstate;
                return 1;
            }

            return Module::handle(m) || 1;

        case FL_RELEASE:
            Fl::selection_owner(0);
            receptive_to_drop = NULL;

            if ( Fl::event_inside( output_connection_handle ) ||
                 Fl::event_inside( output_connection2_handle ) ||
                 Fl::event_inside( input_connection_handle ) )
            {
                if ( _event_state & FL_BUTTON3 )
                {
                    /* was a right click */
                    // TODO: Pop up connection menu.
                }
            }

            return Module::handle(m) || 1;
        case FL_DRAG:
        {
            if ( Fl::event_is_click() )
                return 1;

            int connection_handle = -1;
            if ( Fl::event_inside( output_connection_handle ) )
                connection_handle = 0;
            if ( Fl::event_inside( output_connection2_handle ) )
                connection_handle = 1;

            if ( Fl::event_button1() &&
                 connection_handle >= 0
                 && ! Fl::selection_owner() )
            {
                DMESSAGE( "initiation of drag" );

                char *s = (char*)malloc(256);
                s[0] = 0;
  
                for ( unsigned int i = _connection_handle_outputs[connection_handle][0]; 
                      i < aux_audio_output.size() && i < _connection_handle_outputs[connection_handle][1]; ++i )
                {
                    char *s2;
                    asprintf(&s2, "jack.port://%s\r\n", 
                             aux_audio_output[i].jack_port()->jack_name() );
                    
                    s = (char*)realloc( s, strlen( s ) + strlen( s2 ) + 1 ); 
                    strcat( s, s2 );

                    free( s2 );
                }
               
                Fl::copy(s, strlen(s) + 1, 0);

                Fl::selection_owner(this);

                free( s );

                Fl::dnd();

                return 1;
            }
            
            return 1;
        }
        /* we have to prevent Fl_Group::handle() from getting these, otherwise it will mess up Fl::belowmouse() */
        case FL_MOVE:
            if ( Fl::event_inside( output_connection_handle ) ||
                 Fl::event_inside( output_connection2_handle ) ||
                 Fl::event_inside( input_connection_handle ) )
            {
                fl_cursor( FL_CURSOR_HAND );
            }
            else
                fl_cursor( FL_CURSOR_DEFAULT );

            Module::handle(m);
            return 1;
        case FL_ENTER:
        case FL_DND_ENTER:
            Module::handle(m);
            return 1;
        case FL_LEAVE:
        case FL_DND_LEAVE:
            Module::handle(m);
            if ( this == receptive_to_drop )
            {
                receptive_to_drop = NULL;
                redraw();
            }
            fl_cursor( FL_CURSOR_DEFAULT );
            return 1;
        case FL_DND_RELEASE:
            Fl::selection_owner(0);
            receptive_to_drop = NULL;
            redraw();
            return 1;
        case FL_DND_DRAG:
        {
            if ( this == receptive_to_drop )
                return 1;

            if ( aux_audio_input.size() )
            {
     
                receptive_to_drop = this;
                redraw();
                return 1;
            }
                
            return 0;
        }
        case FL_PASTE:
        {
            receptive_to_drop = NULL;
            redraw();

            if ( ! Fl::event_inside( this ) )
                return 0;

            /* NOW we get the text... */
            const char *text = Fl::event_text();

            DMESSAGE( "Got drop text \"%s\"",text);

            if ( strncmp( text, "jack.port://", strlen( "jack.port://" ) ) )
            {
                return 0;
            }
                        
            std::vector<std::string> port_names;

            char *port_name;
            int end;
            while (  sscanf( text, "jack.port://%a[^\r\n]\r\n%n", &port_name, &end ) > 0 )
            {
                DMESSAGE( "Scanning %s", port_name );
                port_names.push_back( port_name );
                free(port_name );
                
                text += end;
            }
            
            for ( unsigned int i = 0; i < aux_audio_input.size() && i < port_names.size(); i++)
            {
                const char *pn = port_names[i].c_str();
                
                JACK::Port *ji = aux_audio_input[i].jack_port();
                
                if ( ji->connected_to( pn ) )
                {
                    
                    DMESSAGE( "Disconnecting from \"%s\"", pn );
                    ji->disconnect( pn );
                }
                else
                {
                    DMESSAGE( "Connecting to %s", pn );
                    ji->connect( pn );
                }
            }
          
            Fl::selection_owner(0);
            return 1;
        }
    }
    
    return Module::handle(m);
}