Échantillon de code : lecture d'une séquence de notes

La classe ToneControl permet de lire une séquence de notes définie par l'utilisateur, d'une durée et à un tempo spécifique sur un terminal BlackBerry.

// "Mary Had A Little Lamb" has "ABAC" structure
// Use block to repeat "A" section
// Tempos ranging from 20 to 508 beats per minute are divided by 4
// to create a tempo modifier range of 5 to 127.
byte tempo_mod = 30; // 120 bpm
// Note duration  ranges from 128 (1/2 note) to 0 (128th of a note)
// with a default resolution of 64.
byte duration  =  8; // Note length 8 (quaver) = 1/8th of a note duration
// Notes are determined from ToneControl.C4 (Middle C),
// which has a value of 60 and a frequency of 261.6 Hz.
byte C4 = ToneControl.C4; // C note value = 60 (middle C)
byte D4 = (byte)(C4 + 2); // D note value = 62 (a whole step)
byte E4 = (byte)(C4 + 4); // E note value = 64 (a major third)
byte G4 = (byte)(C4 + 7); // G note value = 67 (a fifth)
byte rest = ToneControl.SILENCE; // rest 
byte[] mySequence = {
    ToneControl.VERSION, 1, // version 1
    ToneControl.TEMPO, tempo_mod,
    //
    // Start define "A" section
    ToneControl.BLOCK_START, 0,
    //
    // Content of "A" section
    E4, duration, D4, duration, C4, duration, E4, duration,
    E4, duration, E4, duration, E4, duration, rest, duration,
    //
    // End define "A" section
    ToneControl.BLOCK_END, 0, // end of block number 0
    //
    // Play "A" section
    ToneControl.PLAY_BLOCK, 0,
    //
    // Play "B" section
    D4, duration, D4, duration, D4, duration, rest, duration,
    E4, duration, G4, duration, G4, duration, rest, duration,
    //
    // Repeat "A" section
    ToneControl.PLAY_BLOCK, 0,
    //
    // Play "C" section
    D4, duration, D4, duration, E4, duration, D4, duration, C4, duration
};
try{ 
    Player p = Manager.createPlayer(Manager.TONE_DEVICE_LOCATOR); 
    p.realize(); 
    ToneControl c = (ToneControl)p.getControl("ToneControl"); 
    c.setSequence(mySequence); 
    p.start(); 
} catch (IOException ioe) { } 
} catch (MediaException me) { }

Ces informations vous ont-elles été utiles ? Envoyez-nous vos commentaires.