Lumiera  0.pre.03
»edit your freedom«
stave-bracket-widget.cpp File Reference

Go to the source code of this file.

Description

Implementation of drawing code to indicate the structure of nested tracks.

The design of the drawing is inspired by classical score notation, where braces are used to group the staves (or stems) for one instrument (e.g. grand piano, organ), while brackets are used to group the staves of an ensemble (e.g. string quartet, symphony orchestra) The usual typesetting of musical notation relies much on classical design principles, based on the golden ratio Φ, which is known to be perceived as balanced, neutral and unobtrusive.

The design implemented here is built around a vertical double bar line, and the width of this line is used as reference for size calculations; the curved top and bottom cap is enclosed within a bounding box of size Φ², when defining the base width to be 1. The inner tangent of the curved cap will point towards the end of the smaller (inner) vertical line. While this design is quite simple in structure, and rather easy to construct geometrically, deriving all necessary coordinates numerically can be a challenge. To build this implementation, the constraint system of FreeCAD was used to define the relations, and the resulting numbers were picked directly from the resulting XML document, and used both to build a SVG for documentation, and for the constants in this source file. Using the Gtk::StyleContext and the given Cairo::Context, the drawing code derives the size of the defined standard font in device units, and uses this em size as reference to derive a scale factor, which is then applied to the drawing as a whole — taking into account any given vertical size limitations as imposed by the general nested trade head structure.

See also
the FreeCAD document can be found at doc/devel/draw/StaveBracket.FCStd
SVG image doc/devel/draw/StaveBracket.svg for explanation of geometry
explanation on page #TrackStaveBracket in the TiddlyWiki

Definition in file stave-bracket-widget.cpp.

#include "stage/timeline/stave-bracket-widget.hpp"
#include "stage/style-scheme.hpp"
#include "lib/util.hpp"
#include <cmath>

Functions

double anchorLeft (StyleC style, double scale)
 place left anchor reference line to right side of bold bar. More...
 
double anchorLower (StyleC style, double scale, int canvasHeight)
 place bottom cap vertical anchor, mirroring top cap More...
 
double anchorUpper (StyleC style, double scale)
 place top cap vertical anchor, down from canvas upside. More...
 
double baseWidth (StyleC style)
 Setup the base metric for this bracket drawing based on CSS styling. More...
 
int calcDesiredWidth (StyleC style)
 
int calcRequiredWidth (StyleC style, int givenHeight)
 
void connect (CairoC cox, Gdk::RGBA colour, double leftX, double upperY, double lowerY, double width, double scale, std::vector< uint > connectors)
 Indicate connection to nested sub-Track scopes. More...
 
double determineScale (StyleC style, int givenHeight)
 determine the base metric, taking into account the available canvas size. More...
 
void drawBar (CairoC cox, Gdk::RGBA colour, double leftX, double upperY, double lowerY, double scale)
 draw the double bar to fit between upper and lower cap
 
void drawCap (CairoC cox, Gdk::RGBA colour, double ox, double oy, double scale, bool upside=true)
 Draw the curved end cap of the bracket, inspired by musical notation. More...
 
double getAbsoluteFontSize (StyleC style)
 Use contextual CSS style information to find out about the standard font size More...
 

Variables

const double ARC_I_END = 1.2490457723982538
 
const double ARC_I_R = 6.6978115661011230
 
const double ARC_I_TIP = 0.7853981633974485
 
const double ARC_I_XC = -2.5
 
const double ARC_I_YC = -7.3541019662496883
 
const double ARC_O_END = 1.0172219678978512
 
const double ARC_O_R = 8.0574801069408135
 
const double ARC_O_TIP = 0.5535743588970450
 
const double ARC_O_XC = -(3.0 + PHI)
 
const double ARC_O_YC = -6.8541019662496847
 
const double BAR_LEFT = -BAR_WIDTH
 
const double BAR_WIDTH = PHI_MINOR
 
const double BASE_WIDTH_PER_EM = 0.5
 
const uint FALLBACK_FONT_SIZE_px = 12.5
 
const double LIN_LEFT = PHI_MAJOR - LIN_WIDTH
 
const double LIN_WIDTH = PHI_MINSQ
 
const double ORG = 0.0
 
const double PHI = (1.0 + sqrt(5)) / 2.0
 
const double PHI_MAJOR = PHI - 1.0
 
const double PHI_MINOR = 2.0 - PHI
 
const double PHI_MINSQ = 5.0 - 3*PHI
 
const double PHISQUARE = 1.0 + PHI
 
const uint POINT_PER_INCH = 72
 
const double SQUARE_MINOR = 1.0
 
const double SQUARE_TIP_X = PHISQUARE - PHI_MINOR
 
const double SQUARE_TIP_Y = -PHISQUARE
 

Namespaces

 stage
 Lumiera GTK UI implementation root.
 
 stage::timeline
 The timeline display and editing operations.