assets/js/music.js
// with given offset from the start of the measure.
with given offset from the start of the measure.
with given offset from the start of the measure .
function createMeasure(instrument) {
    if (restarted) {
        restarted = false;
    } else if (Math.random() < chanceRepeatMeasure
                && typeof createMeasure.allNotes != 'undefined'
                && createMeasure.allNotes.length > 0) {
        createPartsForMeasureNotes(createMeasure.allNotes, instrument);
        UI.updateNotesUI(true);
        return;
    }
    UI.updateNotesUI(false);
    createMeasure.allNotes = [];
    var availableNotes = scaleNotes;
    var lengthLeft = 4;
    while (lengthLeft > 0) {
        var sectionLength = Math.random() * Math.floor(Math.log2(lengthLeft) + 1);
        sectionLength = Math.pow(2, Math.floor(sectionLength));
        var repeat = sectionLength * 2 <= lengthLeft && Math.random() < chanceRepeat;
        createMeasure.allNotes.push(createSectionNotes(sectionLength, 4 - lengthLeft,
                                                        availableNotes, repeat));
        lengthLeft -= sectionLength;
        if (repeat) {
            lengthLeft -= sectionLength;
        }
    }
    createPartsForMeasureNotes(createMeasure.allNotes, instrument);
}
function createMeasure ( instrument ) { if ( restarted ) { restarted = false ; } else if ( Math . random ( ) < chanceRepeatMeasure && typeof createMeasure . allNotes != 'undefined' && createMeasure . allNotes . length > 0 ) { createPartsForMeasureNotes ( createMeasure . allNotes , instrument ) ; UI . updateNotesUI ( true ) ; return ; } UI . updateNotesUI ( false ) ; createMeasure . allNotes = [ ] ; var availableNotes = scaleNotes ; var lengthLeft = 4 ; while ( lengthLeft > 0 ) { var sectionLength = Math . random ( ) * Math . floor ( Math . log2 ( lengthLeft ) + 1 ) ; sectionLength = Math . pow ( 2 , Math . floor ( sectionLength ) ) ; var repeat = sectionLength * 2 <= lengthLeft && Math . random ( ) < chanceRepeat ; createMeasure . allNotes . push ( createSectionNotes ( sectionLength , 4 - lengthLeft , availableNotes , repeat ) ) ; lengthLeft -= sectionLength ; if ( repeat ) { lengthLeft -= sectionLength ; } } createPartsForMeasureNotes ( createMeasure . allNotes , instrument ) ; }
with given offset from the start of the measure.
with given offset from the start of the measure .
// create a full, half, or quarter measure