Jane wrote: > hello, > > for my project i need a piano widget with 128 keys (12 octaves + 8 > semitones). every key should be clickable and return a value (0-127). also i > need some sort of range indicator because it must be possible to set an > active range of keys (maybe left click selects the lower end and right click > sets the upper end of the range). other than setting multiple ranges and make > those visible, this widget does nothing. > > every range has 4 parameters: low key, high key and low fade, high fade. and > those 4 parameters need to be set for four layers. > > here is an image: http://img46331.pictiger.com/images/17054849/ > > i think that explains it very well. those "layer"-ranges i want to setup. i > could simply use spinners to set this values but thats not so cool and easy, > because the user cannot actually see the ranges and how they overlap and such > things. but that is very important. > > so, where would i start? thank you. ")
Decide, how to implement your piano widget. I can see two rather different approaches: (1) use 128 Fl_Buttons, and put then into a Fl_Group (2) use one widget, probably derived from Fl_Box, and draw the layout yourself. I assume (2), because (1) seems easier at the first glance, but (2) looks more flexible in the way you can do the setup (see below). Now, derive your own widget from Fl_Box, and write a draw() method to draw the keys. This should be rather simple, if you first draw the white keys and draw the black keys on top of them (maybe you need only fl_rect() and fl_rectf() ). The active ranges could be drawn below the keys, as in your picture (fl_polygon() or similar). Next, write your handle() method to get the user input (key clicks). You would need to calculate the position of a key from the x/y mouse coordinates, but that should be rather straight forward (test the black keys first, then the white keys, and this can be done with simple x/y range comparisons). For setting up the ranges, I would suggest to add a radio button group somewhere else, to let the user select normal display, or start setting up range 1-4. After switching to setup mode for a certain range, you could let the user click four keys, and the callbacks from your handle() would fire to let your application know what s/he clicked. If you want to let the user drag a range of keys, then IMHO approach 2 would be much easier to implement, because your handle() method could do this. Left click, right click, double click, and the combination could also help to decide which of the 4 points of a range the user wants to set. Clicking on a previously defined range point and dragging it elsewhere would also be nice (left click for normal range, right click for fade in/out) ? You will find more information on how to do this in the chapters 5-7 at <http://www.fltk.org/doc-1.1/> Albrecht _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

