Thursday, 8 September 2011


So here's how I'm thinking about this. A selection is an object, which contains a list of the staff elements which have been selected. We don't select staff areas, i.e. the container for the actual stave.

The model should manage the selection object, in response to the controller interpreting gestures, e.g.
  • click and hold mouse button gesture with no shift key down means we need to create a selection object; 
  • dragging the mouse while the mouse key remains held creates a visual rectangle and as that rectangle is drawn, any staff elements which fall within it have their selected property set and they are included in the list in the selection object. Only elements which are completely contained within the selection rectangle are included in the selection object;
  • when the mouse key is released, and a selection object exists, the selection object is complete, nothing actually needs to happen as a result of this gesture though;
  • click and hold mouse button with shift key down means start a new visual rectangle for including objects but any objects that become contained within the rectangle get appended to the existing selection object;
The ability to append to a selection means the selected objects need to be represented visually in a manner other than the mouse drag created selection rectangle. The elements could for example be rendered in a different way, e.g. colour blue if selected, or perhaps slightly enlarged (don't know how difficult that is). For now let's decide that unselected elements are black, selected ones are blue.

Keyboard gestures also drive selection actions.
  • Shift and arrow keys draw the same selection rectangle, ie work like the click and hold gesture, with shift down, i.e. append to existing selection else create new. 
  • If you want to unselect the selection a mouse click does that or a keyboard navigation gesture does.
  • Any new input of course will replace a selection, i.e. select 3 notes then enter a new one mean the 3 get deleted and the one new one gets placed at the start of the selection.
  • Navigation gestures need examination. Does down arrow mean go down a line and forget any selection, or does it mean move the selection down? I think it means the former, let's think about a text component example, if you select a bunch of text then hit down arrow the caret moves down and the selection is forgotten.
Probably need to integrate with the cut and paste API, which in turn integrates with that horrible java drag'n'drop API.

Time to cogitate ...

Dynamic X

In the spirit of maintaining the journal, that's the code working to ensure all elements (bar lines, notes, rests etc) placed on the line retain their relative distance apart when the manuscript area is resized, i.e. a dynamic X co-ordinate.

Onwards ...

Wednesday, 7 September 2011

No layout manager and componentResized

Swing does confuse me. It's probably me, not Swing I hasten to add. So I have no layout manager because none of the preset ones work for music staff elements, and writing one looks incredibly complex, especially if you want to reference all the components in the array that you want to lay out.

So I though no problem, no layout manager, implement the ComponentListener interface and when we're resized go figure out what that means to the staff elements contained. Works well, except for when the object is created - as it's created and it's size initially set, it's not technically resizing so no resize event. Means you end up with a component full of mush or empty on first paint, you then need to move it or lose focus and regain - all of those cause a resize event - inconsistent nonsense to me!

So it's been resolved by overriding setBounds(x,y,width,height), which now calls the super, then lays out the contents the way we want. Tracing shows we call setBounds before a repaint so it now all works the way it should. Waste of a couple of hours figuring that out though - or an investment of a couple of hours, that's the right way to think about it isn't it :)

Tuesday, 6 September 2011

Embarrassed to say ...

this is the first post this year. Meaning I've done very little to take this project forward in 9 months. The good news is the break has done my sanity some good and it hasn't taken long to get back up to speed with where I was.

The JMusicComponent is now managing multiple JStaffAreas (each containing a single staff line for pipe band drumming), and there's an array of JStaffElements sitting nicely on the line's they have an affinity to (rather than being contained within - that's important given the way notes interconnect with slurs - think this will be much easier to work with).

The to do list now looks like this:
  • ensure placement of notes and bar lines on a staff line are maintained as percentage of total line length, so that when the user increases (or decreases) the length of the line, the notes space themselves out appropriately
  • Implement UI gestures to trigger actions for creating and deleting staff lines
  • Implement the concept of selection of notes, and actions targeted upon those selections
Onwards ....