Allow editing of instrument row properties.

This commit is contained in:
Jonathan Moore Liles 2008-02-11 16:59:54 -06:00
parent 3607fb5693
commit 83e2cc45ad
6 changed files with 103 additions and 23 deletions

View File

@ -539,7 +539,7 @@ Canvas::redraw ( void )
/** convert pixel coords into grid coords. returns true if valid */ /** convert pixel coords into grid coords. returns true if valid */
bool bool
Canvas::grid_pos ( int *x, int *y ) Canvas::grid_pos ( int *x, int *y ) const
{ {
*y = (*y - m.margin_top - m.origin_y) / m.div_h; *y = (*y - m.margin_top - m.origin_y) / m.div_h;
*x = (*x - m.margin_left - m.origin_x) / m.div_w; *x = (*x - m.margin_left - m.origin_x) / m.div_w;
@ -566,6 +566,20 @@ Canvas::grid_pos ( int *x, int *y )
/* These methods translate viewport pixel coords to absolute grid /* These methods translate viewport pixel coords to absolute grid
coords and pass on to the grid. */ coords and pass on to the grid. */
/** if coords correspond to a row name entry, return the (absolute) note number, otherwise return -1 */
int
Canvas::is_row_name ( int x, int y )
{
if ( x - m.origin_x >= m.margin_left )
return -1;
x = m.margin_left;
grid_pos( &x, &y );
return m.grid->y_to_note( y );
}
void void
Canvas::set ( int x, int y ) Canvas::set ( int x, int y )
{ {

View File

@ -95,8 +95,8 @@ class Canvas : public trackable
uint p1, p2; /* cursors */ uint p1, p2; /* cursors */
} m; } m;
int rtn ( int r ); int rtn ( int r ) const;
int ntr ( int n ); int ntr ( int n ) const;
void _update_row_mapping ( void ); void _update_row_mapping ( void );
cell_t ** _alloc_array ( void ); cell_t ** _alloc_array ( void );
@ -139,7 +139,8 @@ public:
int draw_playhead ( void ); int draw_playhead ( void );
void draw ( void ); void draw ( void );
void redraw ( void ); void redraw ( void );
bool grid_pos ( int *x, int *y ); bool grid_pos ( int *x, int *y ) const;
int is_row_name ( int x, int y );
void unset ( int x, int y ); void unset ( int x, int y );
void adj_color ( int x, int y, int n ); void adj_color ( int x, int y, int n );
void adj_length ( int x, int y, int n ); void adj_length ( int x, int y, int n );
@ -163,13 +164,13 @@ public:
}; };
inline int inline int
Canvas::rtn ( int r ) Canvas::rtn ( int r ) const
{ {
return m.row_compact ? m.rtn[ r ] : r; return m.row_compact ? m.rtn[ r ] : r;
} }
inline int inline int
Canvas::ntr ( int n ) Canvas::ntr ( int n ) const
{ {
return m.row_compact ? m.ntr[ n ] : n; return m.row_compact ? m.ntr[ n ] : n;
} }

View File

@ -47,12 +47,8 @@ async_exec ( const char *cmd )
int int
canvas_input_callback ( O_Canvas *widget, Canvas *c, int m ) canvas_input_callback ( O_Canvas *widget, Canvas *c, int m )
{ {
static int lmb_down;
// MESSAGE( "Hello, my name is %s", widget->parent()->label() ); // MESSAGE( "Hello, my name is %s", widget->parent()->label() );
int ow, oh; int ow, oh;
int x, y; int x, y;
@ -239,11 +235,27 @@ canvas_input_callback ( O_Canvas *widget, Canvas *c, int m )
switch ( Fl::event_button() ) switch ( Fl::event_button() )
{ {
case 1: case 1:
lmb_down = true; int note;
if ( IS_PATTERN && Fl::event_state() & FL_CTRL ) if ( ( note = c->is_row_name( x, y ) ) >= 0 )
c->randomize_row( y ); {
DEBUG( "click on row %d", note );
Instrument *i = ((pattern *)c->grid())->mapping.instrument();
if ( i )
{
ui->edit_instrument_row( i, note );
c->changed_mapping();
}
}
else else
c->set( x, y ); {
if ( IS_PATTERN && Fl::event_state() & FL_CTRL )
c->randomize_row( y );
else
c->set( x, y );
}
break; break;
case 3: case 3:
c->unset( x, y ); c->unset( x, y );

View File

@ -103,6 +103,7 @@ main_window = make_main_window();
seq_window = make_seq_window(); seq_window = make_seq_window();
make_randomization_dialog(); make_randomization_dialog();
make_instrument_edit_dialog();
Fl::add_handler( shortcut_handler ); Fl::add_handler( shortcut_handler );
@ -136,7 +137,7 @@ if ( Fl::event() == FL_SHORTCUT && Fl::event_key() == FL_Escape )
if ( maybe_save_song() ) if ( maybe_save_song() )
quit();} open quit();} open
xywh {790 38 869 801} type Single box PLASTIC_UP_BOX color 37 resizable xclass non size_range {869 801 0 0} visible xywh {773 244 869 801} type Single box PLASTIC_UP_BOX color 37 resizable xclass non size_range {869 801 0 0} visible
} { } {
Fl_Menu_Bar {} {open Fl_Menu_Bar {} {open
xywh {0 0 869 30} color 37 xywh {0 0 869 30} color 37
@ -383,7 +384,7 @@ if ( o->value() == pattern_tab )
} { } {
Fl_Group sequence_tab { Fl_Group sequence_tab {
label Sequence open label Sequence open
xywh {0 98 868 674} color 37 resizable xywh {0 98 868 674} color 37 hide resizable
code0 {update_sequence_widgets();} code0 {update_sequence_widgets();}
} { } {
Fl_Group {} {open Fl_Group {} {open
@ -501,7 +502,7 @@ if ( playlist->length() )
} }
Fl_Slider sequence_progress { Fl_Slider sequence_progress {
label Sequence label Sequence
callback {transport.locate( (tick_t)((double)playlist->length() * o->value()) );} selected callback {transport.locate( (tick_t)((double)playlist->length() * o->value()) );}
xywh {10 698 233 24} type Horizontal labelsize 12 align 1 xywh {10 698 233 24} type Horizontal labelsize 12 align 1
} }
} }
@ -556,7 +557,7 @@ o->maximum( phrase::phrases() );}
} }
Fl_Group pattern_tab { Fl_Group pattern_tab {
label Pattern open label Pattern open
xywh {0 98 868 674} color 37 hide xywh {0 98 868 674} color 37
code0 {update_pattern_widgets();} code0 {update_pattern_widgets();}
} { } {
Fl_Box pattern_canvas_widget { Fl_Box pattern_canvas_widget {
@ -1013,11 +1014,10 @@ You should have received a copy of the GNU General Public License along with thi
} }
} }
} }
Function {make_randomization_dialog()} {open Function {make_randomization_dialog()} {} {
} {
Fl_Window randomization_dialog { Fl_Window randomization_dialog {
label {Randomization Settings} open label {Randomization Settings} open
xywh {841 360 342 98} type Double xywh {740 128 342 98} type Double
code0 {// feel->value( )} code0 {// feel->value( )}
code1 {probability->value( song.random.probability );} non_modal visible code1 {probability->value( song.random.probability );} non_modal visible
} { } {
@ -1050,7 +1050,38 @@ You should have received a copy of the GNU General Public License along with thi
} }
} }
} }
Function {update_pattern_widgets()} {} { Function {make_instrument_edit_dialog()} {open
} {
Fl_Window instrument_edit_dialog {
label {Instrument Edit} open
xywh {669 299 338 191} type Double modal visible
} {
Fl_Box {} {
label {Instrument Row}
xywh {8 15 321 28} box ROUNDED_BOX color 94 labelsize 22 labelcolor 39
}
Fl_Input instrument_name_field {
label Name
callback {instrument_edit_dialog->hide();} selected
xywh {10 70 321 25} selection_color 48 align 1 when 8 textcolor 32
}
Fl_Value_Slider instrument_volume_slider {
label {Volume %}
xywh {10 112 321 27} type Horizontal align 1 maximum 100 step 1 textsize 14
}
Fl_Value_Output instrument_note_field {
label {Note:}
xywh {52 158 43 24}
}
Fl_Return_Button {} {
label Done
callback {instrument_edit_dialog->hide();}
xywh {255 157 76 25}
}
}
}
Function {update_pattern_widgets()} {open
} {
code {if ( ! pattern_settings_group ) code {if ( ! pattern_settings_group )
return; return;
@ -1268,6 +1299,20 @@ if ( p )
// update_pattern_widgets(); // update_pattern_widgets();
}} {} }} {}
} }
Function {edit_instrument_row( Instrument *i, int n )} {open return_type void
} {
code {instrument_note_field->value( n );
instrument_name_field->value( i->note_name( n ) );
instrument_volume_slider->value( i->velocity( n ) );
instrument_edit_dialog->show();
while( instrument_edit_dialog->shown() )
Fl::wait();
i->note_name( n, strdup( instrument_name_field->value() ) );
i->velocity( n, instrument_volume_slider->value() );} {}
}
} }
decl {\#include <Fl/Fl_Single_Window.H>} {public decl {\#include <Fl/Fl_Single_Window.H>} {public
@ -1549,7 +1594,7 @@ return r;} {}
} }
} }
widget_class Triggers {open widget_class Triggers {
xywh {121 31 1278 1003} type Double hide resizable xywh {121 31 1278 1003} type Double hide resizable
code0 {populate();} code0 {populate();}
code1 {\#include <Fl/Fl_Dial.H>} code1 {\#include <Fl/Fl_Dial.H>}

View File

@ -157,3 +157,10 @@ Mapping::type ( void ) const
{ {
return IS_INSTRUMENT ? "Instrument" : "Scale"; return IS_INSTRUMENT ? "Instrument" : "Scale";
} }
bool
Mapping::editable ( void ) const
{
return IS_INSTRUMENT ? true : false;
}

View File

@ -68,6 +68,7 @@ public:
const char * note_name ( int n ) const; const char * note_name ( int n ) const;
int velocity ( int n ) const; int velocity ( int n ) const;
int key ( void ) const; int key ( void ) const;
bool editable ( void ) const;
const char * type ( void ) const; const char * type ( void ) const;