Showing posts with label music. Show all posts
Showing posts with label music. Show all posts

Saturday, November 27, 2010

Chopiner

So, I'm learning Chopin's piano concerto in e, and wrote something simple up to help with the complicated rhythms. If you're ever having rhythm trouble, just compile it in GCC or any other C++ compiler and the rest should be pretty self-explanatory. You'll have to #include iostream, sstream, vector, cmath and assert.h.


using namespace std;
string LH;
string RH;
int nSubBeats;
int timeSig;

struct noteT {
double value;
bool rest;
double position;
};

string GetLine() {
string result;
getline(cin, result);
return result;
}

int GetInteger() {
while(true) {
stringstream converter;
converter << GetLine();

int result;
converter >> result;

if(converter.fail())
cout << "Please enter an integer. ";
else {
char remaining;
converter >> remaining;

if(converter.fail())
return result;
else
cout << "Unexpected character: " << remaining << endl;
}

cout << "Retry: ";
}
}

double Abs(double n) {
return (n<0) ? -n : n;
}

bool CloseEnough(double sum) {
return Abs(1 - sum) < .01;
}

double LCM(double a, double b) {
double A = a;
double B = b;
while (!CloseEnough(1.0-(a-b)))
(a < b) ? a += A : b += B;
return ((int)a - a == 0) ? a : b;
}

int Round(double n) {
int flooring = floor(n);
int ceiling = ceil(n);
return (n - flooring < ceiling - n) ? flooring : ceiling;
}

void PrintfBeat(string hand) {
for (size_t i = 0; i < hand.length(); i++)
hand[i] = '-';

int every = hand.length()/timeSig;
for (size_t i = 0; i < timeSig; i++)
hand[i*every] = '!';

cout << "(The first line is the beat)\n" << hand << endl;
return;
}

void CalculateNoteValue(const string source, noteT &currNote, const int i, int &n) {
while (true) {
if (source[i+n] == '_')
currNote.value /= 2;
else if (source[i+n] == '-')
currNote.value *= 2;
else if (source[i+n] == '.')
currNote.value *= 1.5;
else {
n--;
return;
}
n++;
}

return;
}

double FindModifier(const string source, int &n) {
double modifier = 1;
n++;
while (source[n] == '_' || source[n] == '.' || source[n] == '-' ) {
if (source[n] == '_')
modifier *= .5;
if (source[n] == '.')
modifier *= 1.5;
if (source[n] == '-')
modifier++;
n++;
}
n--;
return modifier;
}

double WhatsTheKPlet(const string source, int &i);

double kPletBracketsSituation(const string source, int i) {
vector bracketedNotes, total;
while (source[i] != ')') {
double currentNoteValue = FindModifier(source, i);
bracketedNotes.push_back(currentNoteValue);
i++;
}

if (source[i+1] != '<') {
int increment;
for (size_t j = 0; j < bracketedNotes.size(); j++) { // Slightly inefficient but more readable and no copied code.
increment = 1;
noteT dummy;
dummy.value = bracketedNotes[j];
CalculateNoteValue(source, dummy, i, increment);
total.push_back(dummy.value);
}
i += increment;
} else if (source[i+1] == '<') {
i += 2;
double kPlet = WhatsTheKPlet(source, i);
string number = "     ";
double divideBy;
int n = 0;
while (source[i+n] != '>') {
number[n] = source[i+n];
n++;
}
i += n;

divideBy = atof(number.c_str());
double multiplier = divideBy/kPlet;

for (size_t j = 0; j < bracketedNotes.size(); j++)
total.push_back(bracketedNotes[j]*multiplier);

} else {
cout << "\nBad input: char \'" << source[i+1] << "\' after \')\'.\nSIGABRT time! Wheeeeeeeeeeeeeeeeeeee";
assert(false);
}

double totalValue = 0;
for (size_t x = 0; x < total.size(); x++)
totalValue += total[x];

return totalValue;
}

double WhatsTheKPlet(const string source, int &i) {
int n = i;
int count = 0;
while (true) {
if (source[n] == ')')
count++;

if (source[n] == '(') {
count--;
if (count == 0) {
n--;
break;
}
}
n--;
}

n += 2;
double kPlet = 0;
while (n <= i - 2) {
if (source[n] != '_' && source[n] != '-' && source[n] != '.' && source[n] != ')' && source[n] != '(' && source[n] != '>' && source[n] != '<') {
double noteModifier = FindModifier(source, n);
kPlet += 1.0*noteModifier;
n++;
} else if (source[n] == ')') {
n++;
} else {
while (source[n] == '(')
n++;

if (source[n+1] == '>')
break;

kPlet += kPletBracketsSituation(source, n);

while (source[n] != ')' && source[n] != '>')
n++;
n += 2;
if (source[n+1] == '>')
n += 2;
if (source[n-1] == '<') {
while (source[n] != '>')
n++;
n++;
}
}
}

while (source[i-1] != '<')
i++;

return kPlet;
}

void CalculateNplet(int &i, const string source, vector &setOfNotes, vector &notes) {
i += 2;

double kPlet = WhatsTheKPlet(source, i);

string number = "      ";
double divideBy;
int n = 0;
while (source[i+n] != '>') {
number[n] = source[i+n];
n++;
}
i += n;

divideBy = atof(number.c_str());
double multiplier = divideBy/kPlet;

for (size_t j = 0; j < setOfNotes.size(); j++) {
setOfNotes[j].value *= multiplier;
notes.push_back(setOfNotes[j]);
}

return;
}

void CalculateCurrentNote(noteT &currNote, const string source, int i, int &increment) {
CalculateNoteValue(source, currNote, i, increment);

if (source[i] == '0')
currNote.rest = true;
else
currNote.rest = false;
return;
}

void WithinBrackets(const string source, int &i, vector &notes) {
vector setOfNotes, within;
i++; // To get past '(' char
while (source[i] != ')') {
if (source[i] == '(') {
WithinBrackets(source, i, within);
i++;

for (size_t j = 0; j < within.size(); j++)
setOfNotes.push_back(within[j]);

within.clear();
}

if (source[i] == ')')
break;

noteT currNote;
int increment = 1;
currNote.value = 1.0 / timeSig;
CalculateCurrentNote(currNote, source, i, increment);
i += increment + 1;

setOfNotes.push_back(currNote);
}

if (source[i+1] == '_' || source[i+1] == '-' || source[i] == '.') {
int increment;
for (size_t j = 0; j < setOfNotes.size(); j++) { // Slightly inefficient but more readable and no copied code.
increment = 1;
CalculateNoteValue(source, setOfNotes[j], i, increment);
notes.push_back(setOfNotes[j]);
}
i += increment;
} else if (source[i+1] == '<') {
int dummy = i;
CalculateNplet(dummy, source, setOfNotes, notes);
i = dummy;
} else {
cout << "\nBad input: char \'" << source.substr(0, i+1) << "\' after \')\'.\nSIGABRT time! Wheeeeeeeeeeeeeeeeeeee";
assert(false);
}
}

bool BadBrackets(string &source) {
int openSmooth = 0;
int openAlligator = 0;

for (size_t i = 0; i < source.length(); i++) {
if (source[i] == ')')
openSmooth--;
if (source[i] == '(')
openSmooth++;
if (source[i] == '<')
openAlligator++;
if (source[i] == '>')
openAlligator--;
}
return  openSmooth != 0 && openAlligator != 0;
}

void VectorizeNotes(vector &notes, const string source) {
for (size_t i = 0; i < source.length(); i++) {
if (source[i] == ' ')
return;

if (source[i] != '(') {
noteT currNote;
int increment = 1;
currNote.value = 1.0 / timeSig;
CalculateCurrentNote(currNote, source, i, increment);
i += increment;
notes.push_back(currNote);
} else {
int dummy = i;
WithinBrackets(source, dummy, notes);
i = dummy;
}
}
return;
}

bool VectorCount(const vector &v, double n) {
for (size_t i = 0; i < v.size(); i++)
if (v[i] == n)
return true;
return false;
}

void RemoveSpaces(string &hand) {
while (hand.find(" ") != -1) {
for (size_t i = 0; i < hand.length(); i++) {
if (hand[i] == ' ') {
string left = hand.substr(0, i);
string right = hand.substr(i+1, hand.size() - 1);
hand = left + right;
}
}
}
return;
}

void ReadHand(vector &notes, string &hand, const string whichHand) {
cout << "Enter notes for the " << whichHand << " hand: ";
while (true) {
hand = GetLine();
if (hand[hand.length()] != ' ')
hand += " ";

if (BadBrackets(hand))
cout << "Unbalanced brackets! Try again: ";
else
break;
}

RemoveSpaces(hand);
VectorizeNotes(notes, hand);
return;
}

int FindNNotes(vector notes) {
vector values;
// Get rid of duplicate note values
for (size_t i = 0; i < notes.size(); i++) {
double value = 1.0/notes[i].value;
if (!VectorCount(values, value)) {
values.push_back(value);
}

}

// Find LCM of all the note values
for (size_t i = 0; i < values.size() - 1; i++) {
values[i] = LCM(values[i], values[i+1]);
values.erase(values.begin() + i +1);
i--;
}

return values[0];
}

void DoHand(vector &notes, string &hand) {
hand = "";
for (int i = 0; i < nSubBeats; i++)
hand += "-";

int numNotes = notes.size();

notes[0].position = 0;
for (size_t i = 1; i < numNotes; i++) {
notes[i].position = (notes[i-1].position + notes[i-1].value);
}

double sum = notes[numNotes-1].position + notes[numNotes-1].value;
if (!CloseEnough(sum)) {
cout << "\nOK, so, you didn't enter a full bar of notes. \nOr more than one. Try compiling and running again!\n";
cout << "SIGABRT time!\n";
assert(false);
return;
}

for (size_t i = 0; i < numNotes; i++) {
if (notes[i].rest == false) {
int index = Round(notes[i].position*hand.length());
hand[index] = 'o';
} else {
hand[notes[i].position*hand.length()] = '_';
int howManyMore = notes[i].value*hand.length();
for (int j = 1; j < howManyMore; j++) {
hand[notes[i].position*hand.length()+j] = '_';
}
}
}

return;
}

void Welcome() {
cout << "Hiya! Enter rhythms for both hands to see how they fit together.\n";
cout << "First, some formatting and syntax info: \n";
cout << "• Notes are assumed to be one beat long\n";
cout << "• Select sets of notes with ( and ). For example: (oooo)\n";
cout << "• Lengthen or shorten a note or set of notes with the following operators:\n '-'(+1 beat)\n '_'(/2)\n '.'(*1.5)\n\n";
cout << "• Make n-plets with alligator mouths; use them after a ')' char. An n-plet is n notes in the time of however many.\n";
cout << "• For example: (ooooo)<2> is ooooo in the time of two beats. That is, five notes (ooooo) in the time of two notes of one beat each.\n";
cout << "• You don't need to mark the notes within an n-plet as sixteenth notes or whatever -- just without any modifications will be fine.\n";
cout << "• If notes within a n-plet are of different lengths, be sure to mark the first number within the alligator mouths as the number of beats within the n-plet.\n";
cout << "• Finally, pretty much any character can signify a note, except for '_', '-', '.', '<', '>', '(', ')' and '0'. (0 signifies a rest).\n";
cout << "Here's an example (In 3-4 time): \nRH is (ooo_)<2>o, LH is ooo. Generates the following: \no---o---o-o----\no----o----o----\n\n";
return;
}

void Simpler() {
cout << "Enter the number of notes played in the hand that has more notes to play: ";
int more = GetInteger();
cout << "Enter the number of notes played in the hand that has fewer to play: ";
int fewer = GetInteger();

string moreH = "";
int totalLength = more * fewer;
for (int i = 0; i < totalLength; i++)
moreH+= "-";

string fewerH = moreH;

for (size_t i = 0; i < fewer; i++)
fewerH[i*more] = 'o';

for (size_t i = 0; i < more; i++)
moreH[i*fewer] = 'o';

cout << moreH << endl << fewerH << endl;
return;
}

int main (int argc, char * const argv[]) {
while (true) {
cout << "Would you like to enter rhythms for both hands (enter '1') or uniform rhythms (enter '2')? ";
string answer = GetLine();
if (answer[0] == '2') {
Simpler();
return 0;
} else if (answer[0] == '1')
break;
}

vector RHnotes, LHnotes;
Welcome();

while (true) {
cout << "\nEnter the number on the top part of the time signature: ";
timeSig = GetInteger();

ReadHand(RHnotes, RH, "right");
ReadHand(LHnotes, LH, "left");

cout << "RH is " << RH << endl;
cout << "LH is " << LH << endl;

double nR = FindNNotes(RHnotes);
double nL = FindNNotes(LHnotes);
nSubBeats = LCM(nR, nL);

DoHand(RHnotes, RH);
DoHand(LHnotes, LH);

cout << "The minimal number of beats to represent the right hand is " << nR << ".\n";
cout << "The minimal number of beats to represent the left hand is " << nL << ".\n";
cout << "The minimum total number of sub-beats is " << nSubBeats << ".\n";
PrintfBeat(RH);
cout << RH << endl;
cout << LH << endl;

cout << "Would you like to do another one? ";
string response = GetLine();
if (response[0] == 'n' || response[0] == 'N')
break;
}
return 0;
}

Saturday, October 16, 2010

16th International Fryderyk Chopin Competition

The competition only happens every five years! It's been going on since October 3, now. The finals start in two days! This is basically the most prestigious piano competition that exists today. Martha Argerich (a former winner of the competition) is one of the judges! Participants must be between 17 and 30 years old. By the time one gets to the finals, they will have learnt nineteen pieces (all by Chopin) from a selection of about... 40? Ten people qualified for the finals, and there were 80 at the start. For the final, they have to play one of the two concertos, with an orchestra instead of a second piano reduction, I think.

There's a live broadcast going on (resumes on Monday); it's definitely worth a listen. The Chopin concertos are super-awesome. I'm currently learning one of them, Op. 11 in e.

As an aside, Yundi Li (李云迪), who I'm going to hear play the Tchaikovsky concerto in the Spring in SF, won this competition at 18. He was the first person to win the first prize in 15 years.

Wednesday, October 13, 2010

Prokofiev concerto 2 and Flight of the Bumblebee

This must be the most technically impressive piano playing I've ever seen in my life. Here's Wang Yujia (王羽佳) playing the second movement of Prokofiev's second concerto and, for an encore, Cziffra's arrangement of Flight of the Bumblebee. In the Prokofiev, by the way, that movement has the right hand and left hand playing almost 1500 16th-notes each in under 3 minutes, or basically 10 notes per second, both hands together.

That's the kind of finger independence each pianist wishes for: each finger on each of her hands is controlled completely individually! And look at how relaxed her hands are throughout! It's just astounding. Check out 6:55-7:00, especially.

By the way, that's Michael Tilson Thomas conducting -- he's the head conductor of the San Francisco Symphony Orchestra, a nearby orchestra I go to often (just heard Beethoven 7 and on Oct. 24 is Beethoven piano concerto 4).

Tuesday, September 28, 2010

Tuesday, September 7, 2010

Beethoven Op. 81a

There's a YouTube video of Daniel Barenboim playing Beethoven's 26^th piano sonata! First movement and part of second here, and here's the rest of the second and the whole third movement (attacca).

He plays the first movement with a crazy amount of rubato, but it is a very Romantic-style movement, and, after all, he's Daniel Barenboim; he can do whatever the heck he wants. His playing of the second and third movements is absolutely perfect. Look how relaxed his hands are! What an incredible pianist.

Thursday, September 2, 2010

So Much Sheet Music

Just got back from Taiwan (didn't have internet access, which explains the recent paucity of posts)! In 台北I got to go to a sheet music store, called 大陆书店。They had so much music, and it was quite decently priced. I was like a kid in a candy store, except I'm 20 (still a kid, then) and in a music store, haha. I got enough to keep me busy for... quite a while, I'd say:


In case that's too small to read, that's Schumann's piano concerto, Mozart piano concertos 9, 19, 21 and 24, Beethoven piano concertos 4 and 5, Haydn's D major piano concerto, Bach's E major piano concerto (transcribed from F major for Oboe? It's BWV1053), The Goldberg Variations, Debussy's Children's Corner suite, Mozart fantasias and rondos, Busoni's transcription of Bach's second violin partita's fifth movement, Gershwin's Rhapsody in Blue and Mendelssohn's Songs Without Words. All the concertos (and the Gershwin) are first piano plus second piano orchestra reduction editions!

And here's all the piano music they had:


:D

Tuesday, August 31, 2010

10 Best Pieces of All Time / 10 Favourite Pieces

I was asked this the other day. What a hard question! My tentative answer (in decreasing order of awesomeness):

(Mozart) piano concerto no. 23 in A, K.488
(Bach) Brandenburg concerto no. 4 in G, BWV 1049
(Beethoven) piano concerto no. 4 in G, Op. 58
(Beethoven) piano sonata no. 26 in Eb, Op. 81a
(Mozart) piano sonata no. 12 in F, K. 332
(Schumann) piano concerto in a, Op. 54
(Haydn) cello concerto no. 2 in D, Hob. VIIb
(Mozart) fantasia in c, K. 475
(Chopin) piano concerto no. 1 in e, Op. 11
(Rachmaninov) piano concerto no. 2 in c, Op. 18

I also reallyreallyreally really like (in no particular order):
(Mozart) piano concerto no. 9 in Eb, K. 271
(Chopin) Étude no. 6 in g#, Op. 25
(Bach) violin partita no. 2 in d, BWV 1004
(Mozart) piano concerto no. 19 in F, K. 459
(Bach) concerto no. 2 in E, BWV1053
(Haydn) piano sonata no. 52 in Eb, Hob. 16
(Bach) piano partita no. 2 in c, BWV826
(Mozart) piano concerto no. 21 in C, K. 467
(Mozart) piano quartet no. 2 in Eb, K. 493
(Mozart) piano quartet no. 1 in g, K. 478
(Beethoven) piano sonata no. 21 in C, Op. 53
(Beethoven) piano sonata no. 23 in f, Op. 57
(Beethoven) triple concerto in C, Op. 56
(Bach) Goldberg Variations, BWV 988
(Mozart) Requiem in d, K. 626
(Bach) English, French, Cello suites
(Schubert) violin sonatas

This would be a good time to mention my favourite keys: Eb and d. And you people (pieces and keys)?

Also, a random musing: when learning a movement of a piece, to what degree is one obliged to also learn the other movements? I should think, obviously it's preferable, because it helps you put what you're playing in context: the movements were meant to be read, played, heard, however you experience it, together. I'm pretty sure most people listen to all the movements of a piece together, but learning two or more other movements is no mean feat. Hmm?

Sunday, July 11, 2010

So You Want to Write a Fugue


This is awesome. Glenn Gould, undoubtedly the best Bach pianist ever (except for Bach himself, who was in his time a world-renowned organist and possibly the best improviser ever -- he composed a six-part fugue from scratch in his head as he was playing it, on command by Fréderic The Great. It ended up becoming his Musical Offering) , composed this four-part fugue (SATB and strings accompaniment) in 1963. In the first recording, the strings were the Juliard String Quartet!

Here are the lyrics (and here's the link) :
So you want to write a fugue.
You got the urge to write a fugue.
You got the nerve to write a fugue.
So go ahead, so go ahead and write a fugue.
Go ahead and write a fugue that we can sing.
Pay no heed, Pay no mind.
Pay no heed to what we tell you,
Pay no mind to what we tell you.
Cast away all that you were told
And the theory that you read.
As we said come and write one,
Oh do come and write one,
Write a fugue that we can sing.
Now the only way to write one
Is to plunge right in and write one.
Just forget the rules and write one,
Just ignore the rules and try.
And the fun of it will get you.
And the joy of it will fetch you.
Its a pleasure that is bound to satisfy.
When you decide that John Sebastian must have been a very personable guy.
Never be clever
for the sake of being clever,
for the sake of showing off.
For a canon in inversion is a dangerous diversion, 
And a bit of augmentation is a serious temptation,
While a stretto diminution is an obvious allusion.
For to try to write a fugue that we can sing.
And when you finish writing it
I think you will find a great joy in it.
or so...
Nothing ventured, nothing gained they say
But still it is rather hard to start.
Well let us try right now.
Now we are going to write a fugue.
We are going to write a good one.
We are going to write a fugue ... right now.

Wednesday, July 7, 2010

Mihail Pletnev Accused of Raping a 14-year-old Boy in Thailand

Gosh, I hope it ends up being false. Pletnev is a great Russian pianist, though there are a bunch of those. He founded the Russian National Orchestra and has a bunch of wonderful recordings out there. He also composes and conducts! He received Государственная Премия Российской Федерации, the highest award given by the Russian government to musicians.

Friday, June 25, 2010

Coming to like Rachmaninov (slowly) ?

Last year's winner of the Stanford Concerto Competition had their concert during Spring quarter this most recent academic, as always. When I went to the concert last year, the pianist (Jack Yang, then a Junior, if you know him) played Beethoven's fifth piano concerto, a really pretty, monstrously large piece. 'in my favourite key, too: Eb major. Anyway, the soloist for this most recent concert, whose name I can't remember, played Rachmaninov's third piano concerto. Before this I'd never listened to any Rachmaninov before, but the first movement, at least, stuck in my mind.

I started listening to music when I was about seventeen. For three or so months, I listened to what my dad listened to -- R&B and rock from when he grew up. Co-incidentally, at this time, I became more serious about playing piano. My previous teacher, from when we were in Russian, had never taught me anything about technique or interpretation. Or sight-reading, for that matter: I sight-read really terribly. After my first five years of playing, I was under the impression that to play a piece well was to play it as ostentatiously as possible, at the greatest speed possible while paying no attention to dynamics.

When we arrived in South Africa, my new teacher worked hard to undo everything my previous teacher had taught me. Eventually, she gave me had some impact. At this point, my dad started to like classical music, given that I was playing better. I then followed him. We started out listening to Alicia de Laroccha's really pretty recordings of the Mozart piano sonatas and then branched out slowly. When I got to college, I thought Beethoven was way too late a composer for me to like, 'cause I only liked Mozart (who still remains my favourite composer) and Bach (second-favourite) and Haydn. Slowly, through influence from friends, I came to like later and later composers. I would have said I've reached my limit with Chopin. Until, that is, I heard Rach 3. It seems, now, quite conceivable that I could eventually come to like some of Rachmaninov's music, even though I'd always dismissed him as "hotel music" or "elevator music." Part of it may be that he reminds me of Russia; I'm finding myself occasionally listening to some Tchaikovsky, too.

Perhaps I can no longer divide my music tastes purely chronologically: Liszt , for example, lived almost completely before Rachmaninov, yet I'm about as convinced as I can be that I'll never come to love his music. I can't group it as dissonant vs. non-dissonant, either, though that was once the case. Mozart, even, uses dissonance in wonderfully interesting ways -- just look at the C major string quartet or his absolutely gorgeous c minor fantasia.

What is it that makes composers like Liszt, Prokofiev, Stravinsky, Britten, Adams and others so different, then? They're different from each other, too. As much as I'd like to say that their music, collectively, just sounds random, it clearly isn't.

If I had to guess, I'd say that by far the majority of my musical friends are Romantic-era - oriented, with just a few Modern-oriented (modern classical) and even fewer preferring Baroque- and Classical-era music.

Wednesday, June 23, 2010

Schumann's piano concerto

I was digging through music files the other day, and ran into Schumann's piano concerto, in a. It's a really pretty piece! I think I might try it this Summer. Here's what it sounds like, played by Svyatoslav Richter, one of my favourite pianists:

: I. Allegro Affetuoso (first link, second link)
: II. Intermezzo, which is attacca
: III. Allegro Vivace

The third movement is in 3/4, but if you listen carefully, sometimes it's interestingly ambiguous. And it's way fast, too, so no good for waltzing :(

Schumann tried two piano concerti before this, but neither worked out, apparently. This one was written for his wife, Clara Schumann, who was an amazing pianist. She even wrote some cadenzas for other concertos, including Mozart's 20^th. Supposedly Grieg used this one as a model for his concerto.

Thursday, June 17, 2010

Vuvuzelas


With the World Cup going on and all, there's naturally a lot of vuvuzela-blowing going on. Vuvuzelas, in case you don't know, are these long plastic horn-like instruments that produce a most wonderful loud sound. They're common at rugby and soccer games back in SA.

If you've ever played Legend of Zelda, another cool puzzle video game, you'll find this funny.

For those with CS interest, here's how you can selectively mute out the vuvuzela sound through equalizers (though I don't know why you would ever want to do that) .

Here's some information on how they work and why they're "annoying:" http://www.newscientist.com/article/dn19041-what-makes-the-sound-of-vuvuzelas-so-annoying.html?full=true&print=true

And last, but not least, Vuvuzela Hero! I would totally play this all day. This reminds me of a discussion with some friends earlier this academic year; we were hoping someone would someday make Orchestra Hero or Harpsichord Hero.