Musical Temperaments
My Tuner app uses equal temperament because that is the current standard and it is relatively easy to calculate using double precision arithmetic and maths library functions. First, declare some constants.
private static final int OCTAVE = 12;
private static final int EQUAL = 8;
private static final int A_OFFSET = 9;
private static final int C5_OFFSET = 57;
The calculation first produces the cents relative to the reference, usually 440Hz. Then the note number with an added constant because octaves start at C, not A. Then the reference frequency for that note, then the cents difference.
Read more →Draw Musical Staff
A musical staff is not a trivial thing to draw because of the complex curves needed for the treble and bass clef. What is needed is a source of vector drawing coordinates.
The data used was originally intended for use in postscript, so the vertical axis is reversed.
// Treble clef
private static final float tc[][]=
{
{-6, 16}, {-8, 13}, {-14, 19}, {-10, 35}, {2, 35}, {8, 37},
{21, 30}, {21, 17}, {21, 5}, {10, -1}, {0, -1}, {-12, -1},
{-23, 5}, {-23, 22}, {-23, 29}, {-22, 37}, {-7, 49}, {10, 61},
{10, 68}, {10, 73}, {10, 78}, {9, 82}, {7, 82}, {2, 78},
{-2, 68}, {-2, 62}, {-2, 25}, {10, 18}, {11, -8}, {11, -18},
{5, -23}, {-4, -23}, {-10, -23}, {-15, -18}, {-15, -13},
{-15, -8}, {-12, -4}, {-7, -4}, {3, -4}, {3, -20}, {-6, -17},
{-5, -23}, {9, -20}, {9, -9}, {7, 24}, {-5, 30}, {-5, 67},
{-5, 78}, {-2, 87}, {7, 91}, {13, 87}, {18, 80}, {17, 73},
{17, 62}, {10, 54}, {1, 45}, {-5, 38}, {-15, 33}, {-15, 19},
{-15, 7}, {-8, 1}, {0, 1}, {8, 1}, {15, 6}, {15, 14}, {15, 23},
{7, 26}, {2, 26}, {-5, 26}, {-9, 21}, {-6, 16}
};
// Bass clef
private static final float bc[][] =
{
{-2.3f,3},
{6,7}, {10.5f,12}, {10.5f,16},
{10.5f,20.5f}, {8.5f,23.5f}, {6.2f,23.3f},
{5.2f,23.5f}, {2,23.5f}, {0.5f,19.5f},
{2,20}, {4,19.5f}, {4,18},
{4,17}, {3.5f,16}, {2,16},
{1,16}, {0,16.9f}, {0,18.5f},
{0,21}, {2.1f,24}, {6,24},
{10,24}, {13.5f,21.5f}, {13.5f,16.5f},
{13.5f,11}, {7,5.5f}, {-2.0f,2.8f},
{14.9f,21},
{14.9f,22.5f}, {16.9f,22.5f}, {16.9f,21},
{16.9f,19.5f}, {14.9f,19.5f}, {14.9f,21},
{14.9f,15},
{14.9f,16.5f}, {16.9f,16.5f}, {16.9f,15},
{16.9f,13.5f}, {14.9f,13.5f}, {14.9f,15}
};
Both these sets of points are made up of an initial move, followed by a series of cubic bezier curves. The bass clef has three sections, the symbol, followed by the two dots.
Read more →Expand Android Selection
When editing data or source files it would be useful to have selections triggered by a double tap or long press expand to enclosing delimiters or brackets.
There is a section in the Android docs which explains how to set up your own context menu or contextual action mode, but not how to change the selection.
This method is fine if you have only one text editor view in your app, but would be difficult with more than one as there is no way to identify the originating view. In Java a regular expression (regex) can only search forwards, but not backwards, so we search forwards using a regex, work out what to look for backwards, and use a standard string reverse search to find the start of the extended selection. The regex contains bracket characters and quote characters. If the forward search finds an opening bracket, we don’t change the selection. If the extended selection contains a newline we don’t change the selection because we have probably got a closing quote on one line and an opening quote on another. If the delimiter is a semicolon we look back for a newline.
Read more →Create PDF Report
Introduction
As part of the Questionnaire Maker plugin it is necessary to
create a pdf report. The best tool to do this appears to be
TCPDF, which appears to be part of at least some Linux
distributions as php-tcpdf
. It is not included in WordPress.
Implementation
As both the plugin and TCPDF are hosted on GitHub, the best way to implement the plugin, and TCPDF if it is not available on the web server, is to clone the repositories and use symbolic links to provide the plugin and the library in the right places. The same method could be used to implement WordPress.
Read more →Questionnaire Maker
Introduction
Questionnaire Maker is a WordPress and Hugo plugin that asks a series of questions and produces a PDF report. The project is on Github.
Documentation
The plugin uses the shortcodes [questionnaire-questions]
and
[questionnaire-report]
, or {{< questionnaire-questions >}}
and
{{< questionnaire-report >}}
. The shortcode will be replaced on the
page with a series of panels containing the questions and options for
the answers, or a panel with a preview of the report.