[kln2-devel] PianoKeyboard,NameButtonsBox,BaseMusicNote
Brought to you by:
wiecko
From: Marek W. <Mar...@fu...> - 2004-03-07 01:02:09
|
Hi e-body. I just wanted to let you all know, that I did some major changes in the kln2. Parts which have already been there were almost not modified, so what you are working on should be little affected (although will have to be modified in future to get full advantage of the changes). Please, report any problems. =========================== First of all, I included a new class BaseMusicNote. This holds many static functions for conversion of e.g. a form with note+accidental to midi pitch, returning number of the note in octave (0 for ANY C, 1 for ANY C# or Db and so on), returning QString of a note name dependent on "enum Notation {English, German}" and things like this. Extra methods of this kind will have to be added in future. Please, for any such a conversion needed, add a new method into BaseMusicNote. I think we needed such an abstraction of a music note. Current 'Note' class is too much connected to staff canvas picture. And many abstract note properties were scattered all through the code. ========================== Another change affects the structure of the code very much. Now, let's think about future exercises. They re-use the same kinds of widgets. Example: There is now a note-to-name exercise : you see a note in the staff, and you choose it's name from namebuttons. But there will be e.g. note-to-fret exercise : you see a note in the staff (so the staff canvas is used again) and you should find an appropriate PieceOfFret (a one-note place on the fretboard). And there may be a fret-to-name exercise: you see a PieceOfFret highlighted (fretboard reused) and should choose appropriate namebutton (namebuttons reused). Basically, what I am trying to say is : there will be only few different elements just used in different configurations. In the form in which it is written now it would be quite hard to implement. The nameButtons, the staff canvas etc. are direct properties of KLearnNotes2 class. Therefore, their initialization makes the code quite complicated (anybody who read KLearnNotes2 constructor knows, it takes a pen and a big piece of paper to figure out which layout corresponds to which widgets and where it is placed in the main window). This makes any modifications quite complicated. Plus, all the elements have to know about each other: did you noticed, that one of arguments of ClickableView constructor is ... KLearnNotes2* ??? And it runs KLearnNotes2 class methods directly! (grep for "papcio->isStarted()"). I guess this is one of the best candidates for the bottle of wine contest (do you remember my introductory kln2-devel e-mail? :) . Nope, that's not the way things should be done. * All self contained elements should be extracted into separate classes (NameButtonBox, Staff, PianoKeyboard, GuitarFretboard etc.). * They should not run each other methods directly; rather, they should emit signals informing about what an user is doing and let the exercise setup decide how to react on this (that is, to which slots of which objects connect these signals). OK. So I did it for the two simplest examples: PianoKeyboard and NameButtonBox. I also added examples of these to the KLearnNotes2 constructor, so that you could see how they are used (see the attached screenshot). I DO NOT INTEND TO KEEP THEM DISPLAYED THIS WAY. This is added temporarily just to show you what's new. What to look at? First of all, look at the end of KLearnNotes2 constructor. The PianoKeyboard and NameButtonBox are created, added and set up (signals are connected to some slots) just in few lines of code! What a difference compared to the complicated setup of the old buttons/canvas ! Basically, everything that deals with placement of buttons/piano keys (="everything messy") is done in the PianoKeyboard and NameButtonBox classes. Second thing: you will see in standard output info about all signals emitted (just click on the piano keys/nameButtons). As you see, they are much more detailed than what is really used right now, so more detailed user action handling will be quite easy too. And the third thing: new files musicwidget.{h,cpp} and modifications of KLNfancywidgets.{h,cpp} are examples of usage of BaseMusicNote class. ========================== This is the very crude first version of the new classes. If you look at the code you will see that many methods are not written yet (they are just "{}"). RandomObject stuff should be handled within the classes. Also, I didn't write comments for all the methods/members yet. ~Marek PS: For those with slow i-net connection: updating Makefile.am basemusicnote.cpp klearnnotes2.cpp musicwidget.h Makefile.in basemusicnote.h musicwidget.cpp KLNcanvasitems.cpp KLNcanvasitems.h KLNfancywidgets.cpp KLNfancywidgets.h globals.h and, because of recent Mo's commits: klearnnotes2.h in src/ should be enough. -- \/ /|\ Marek Wieckowski ##### | | | = . . = \|/ Institute of Theoretical Physics U | Warsaw University / ~ \___ | <| | | > . < | http://www.fuw.edu.pl/~wiecko <<___>> | http://klearnnotes2.sourceforge.net |