Skip to content

Commit

Permalink
Random Root Prefs
Browse files Browse the repository at this point in the history
Added Pref model to store user prefs, random root preferences set.
  • Loading branch information
deltadada committed Oct 8, 2014
1 parent 215c6c7 commit 3d50648
Show file tree
Hide file tree
Showing 50 changed files with 4,651 additions and 18 deletions.
87 changes: 87 additions & 0 deletions PrefModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
var INTSCHEME_A = "A";// constant
var INTSCHEME_B = "B";// constant

var PrefModel = {

// intScheme : INTSCHEME_A
// ,
// rrq_LoFret : 0
// ,
// rrq_HiFret : 0
// ,
// rrq_Notegroups : []
// ,
notegroups: []
,
aPrefs :
{
intScheme : INTSCHEME_A,
rrq_LoFret: 0,
rrq_HiFret: 19,
rrq_LoStr: 1,
rrq_HiStr: 6,
rrq_Notegroups : [],
},
init : function(aNotegroups, maxFret, maxString){
this.aPrefs.rrq_HiFret = maxFret;
this.aPrefs.rrq_HiStr = maxString;
for(ng in aNotegroups){
// Note: only pushing scales not arps or anything else
this.aPrefs.rrq_Notegroups.push([dictScales[ng].ngtype+'_'+dictScales[ng].varname, true]);
}
}
,
usingUserPrefs:false
,
writePrefCookie : function(){
// put form values in mPref.aPrefs and save to cookie, or local storage if chrome

// random root
mPref.aPrefs.rrq_LoFret = $('#spRR_LoFret').spinner().spinner( "value" );
mPref.aPrefs.rrq_HiFret = $('#spRR_HiFret').spinner().spinner( "value" );
mPref.aPrefs.rrq_LoStr = $('#spRR_LoStr').spinner().spinner( "value" );
mPref.aPrefs.rrq_HiStr = $('#spRR_HiStr').spinner().spinner( "value" );
// go through Notegroup inputs in the preferences popup and align with aPrefs.rrq_Notegroups
// 0 is name and 1 is true or false (checked or unchecked)
for (var ng in mPref.aPrefs.rrq_Notegroups){
if($('#prefRRQ_'+mPref.aPrefs.rrq_Notegroups[ng][0]).is(':checked')){
mPref.aPrefs.rrq_Notegroups[ng][1] = true;
} else{
mPref.aPrefs.rrq_Notegroups[ng][1] = false;
}
}


// local chrome will not save cookies
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
//set cookies
if(is_chrome)$.localStorage('fs_userPrefs', this.aPrefs);
else $.cookies.set('fs_userPrefs', this.aPrefs);
}
,
retrieveUserPrefs : function(){
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

//get cookies
var fs_userPrefs=(is_chrome)?$.localStorage('fs_userPrefs'):$.cookies.get('fs_userPrefs');
if(fs_userPrefs!=null){
this.aPrefs = fs_userPrefs;
this.usingUserPrefs = true;
}
//alert( fs_userPrefs +' '+fs_userPrefs.rrq_LoFret+' '+fs_userPrefs.rrq_HiFret);

}
,
notegroupInPrefs : function(ngKey){
var rBool = false;
var nGrps = this.aPrefs.rrq_Notegroups
for(ng in nGrps){
if(ngKey == nGrps[0][0].varname){
rBool = true;
}
}
return rBool;
}


}
2 changes: 1 addition & 1 deletion ScaleDictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ var INTCLR_AEOLIAN = ["i_root", "white","black","i_third","white","black","white
var INTCLR_PHRYGIAN = ["i_root","black","white","i_third","white","black","white","i_fifth","black","white","i_seventh","white"];
var INTCLR_LOCRIAN = ["i_root","black","white","i_third","white","black","i_fifth","white","black","white","i_seventh","white"];
var INTCLR_AEOLIAN = ["i_root", "white","black","i_third","white","black","white","i_fifth","black","white","i_seventh","white"];
var INTCLR_SYMDIM = ["i_root", "black","white","i_third","black","white","black","i_fifth","white","black","i_seventh","white"];
var INTCLR_SYMDIM = ["i_root", "black","white","i_third","black","white","i_fifth","black","white","i_seventh","black","white"];
var INTCLR_MINHARM = ["i_root", "white","black","i_third","white","black","white","i_fifth","black","white","white","i_seventh"];
var INTCLR_MINMEL = ["i_root", "white","black","i_third","white","black","white","i_fifth","white","black","white","i_seventh"];
var INTCLR_ALTERED = ["i_root", "black","white","i_third","black","white","i_fifth","white","black","white","i_seventh","white"];
Expand Down
169 changes: 158 additions & 11 deletions boxfrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
//

var CHECKANSWER = 'Check Answer!';

var GTR_FRETS = 19;
var GTR_STRINGS = 6;
var GUITAR_STRINGS; // will be array of strings
var INTERVAL_COLORS = [
"i_root",
Expand Down Expand Up @@ -667,17 +668,53 @@ var ctl_newIntQuiz = function(){

var ctl_newRandRoot = function(){
clear_fretboard();
//INTERVALMODE = false;
//get random scale
// get randonm note on FB
var note = get_random_stringFret(); // 0 = string, 1 = fret
td_paint('#'+'nc_'+note[0]+'_'+note[1], "red");
var sKey = getKeyObjFromNoteName($('#'+'nc_'+note[0]+'_'+note[1]).attr('notename')).safename;
var ng = get_random_scale_notegroup_key() // gets random dictionary key from scaleDict
arrNg = ng.split('_');
// random string, fret according to mPrefs
var lowFret = mPref.aPrefs.rrq_LoFret;
var highFret = mPref.aPrefs.rrq_HiFret;
var lowString = mPref.aPrefs.rrq_LoStr -1;
var highString = mPref.aPrefs.rrq_HiStr -1;
var stringFret= [-1, -1];// random string/fret
while(!(stringFret[0] >= lowString && stringFret[0] <= highString)){
stringFret[0] = Math.floor((Math.random() * GUITAR_STRINGS.length) );// string
}
while (!(stringFret[1] >= lowFret && stringFret[1] <= highFret)){
stringFret[1] = Math.floor(Math.random() * highFret );
}
td_paint('#'+'nc_'+stringFret[0]+'_'+stringFret[1], "red");
var sKey = getKeyObjFromNoteName($('#'+'nc_'+stringFret[0]+'_'+stringFret[1]).attr('notename')).safename;

// get random dictionary notegroup key that is in user preferences
checkedNG =[];// notegroups checked in preferences
for(ng in mPref.aPrefs.rrq_Notegroups){
if(mPref.aPrefs.rrq_Notegroups[ng][1]){
checkedNG.push(mPref.aPrefs.rrq_Notegroups[ng][0]);
}
}
var arrNg = checkedNG[Math.floor((Math.random() * checkedNG.length))].split('_');
set_notes_per_notegroup(sKey, arrNg[0] , arrNg[1])
}

// check boxes according to Pref model
var ctl_updateRRQprefView = function(){
for (var ng in mPref.aPrefs.rrq_Notegroups){
//0: scale name, 1: t/f checked in prefs
if(mPref.aPrefs.rrq_Notegroups[ng][1]){
// control eg 'prefRRQ_SC_DORIAN'
$('#prefRRQ_'+mPref.aPrefs.rrq_Notegroups[ng][0]).prop('checked', true);
}else{
$('#prefRRQ_'+mPref.aPrefs.rrq_Notegroups[ng][0]).prop('checked', false);
}
}
};

//when dialog is closed, update the Pref model with data in popup form controls
var ctl_updatePrefs = function(){
//RandomRootQuiz
mPref.rrq_LoFret = $("#spRR_LoFret").spinner( "value" );
mPref.rrq_HiFret = $("#spRR_HiFret").spinner( "value" );
mPref.writePrefCookie();

};

// more utilities
//
Expand Down Expand Up @@ -924,6 +961,25 @@ var populateNotegroupsUnabridged = function(){

};

var populateNotegroupsRandRootTab = function(){
var itemsPerCol =7;
var colItem=0;
html="";
html+='<span class="RR_scaleOptionsCol">';
for (var ng in mPref.aPrefs.rrq_Notegroups){
colItem = colItem+1;
if(colItem > itemsPerCol){
html+='</span><span class="RR_scaleOptionsCol">';
colItem = 1;
}
ng = dictScales[mPref.aPrefs.rrq_Notegroups[ng][0]]; // 0 is name, 1 is t/f for checked box
html += '<input type="checkbox" id="prefRRQ_'+ng.ngtype+'_'+ng.varname+'" name="'+ng.ngtype+'_'+ng.varname+'" value="'+ng.ngtype+'_'+ng.varname+'"> '+ng.name+'<br>';
}
html+='<span class="RR_scaleOptionsCol">';
$("#RR_scaleOptionsDiv").append(html);
};


// Unabridged divs are the notegroup div objects in the left hand div under the fretboard
// with all the tabs for each key. These are all the scales and arpeggios, unabridged.
// These become draggable over to the right hand div under the fretboard which is governed by
Expand Down Expand Up @@ -1001,8 +1057,10 @@ jQuery(document).ready(function() {
$( ".cNoteGroup" ).draggable({ addClasses: false });



// make fretboard
$(gen_fret_boxes(19, 6)).insertAfter($('#mainfretboard'));

$(gen_fret_boxes(GTR_FRETS, GTR_STRINGS)).insertAfter($('#mainfretboard'));
GUITAR_STRINGS = getFretcloneStrings();
set_notes();

Expand All @@ -1020,6 +1078,51 @@ jQuery(document).ready(function() {
}
$('#fretclone > tbody:last').append(newRow);


// instantiate prefsModel -- for user preferences to govern and be saved as cookie or storage
mPref = PrefModel;
mPref.init(dictScales, GUITAR_STRINGS[0].length, GUITAR_STRINGS.length); // notegroups array, maxFrets, maxStrings


// make tabs in popup
$("#prefTabs").tabs();

// set up RandomRoot quiz prefs
var spRR_LoFret = $( "#spRR_LoFret" ).spinner({
min: mPref.aPrefs.rrq_LoFret,
max: mPref.aPrefs.rrq_HiFret,
value: mPref.aPrefs.rrq_LoFret
});
var spRR_HiFret = $("#spRR_HiFret").spinner({
min: mPref.aPrefs.rrq_LoFret,
max: mPref.aPrefs.rrq_HiFret,
value: mPref.aPrefs.rrq_HiFret
});
var spRR_LoStr = $("#spRR_LoStr").spinner({
min: mPref.aPrefs.rrq_LoStr,
max: mPref.aPrefs.rrq_HiStr,
value: mPref.aPrefs.rrq_LoStr
});
var spRR_HiStr = $("#spRR_HiStr").spinner({
min: mPref.aPrefs.rrq_LoStr,
max: mPref.aPrefs.rrq_HiStr,
value: mPref.aPrefs.rrq_HiStr,
});

// set up prefs per user cookie or default
mPref.retrieveUserPrefs();

spRR_LoFret.spinner("value",mPref.aPrefs.rrq_LoFret);
spRR_HiFret.spinner("value",mPref.aPrefs.rrq_HiFret);
spRR_LoStr.spinner("value",mPref.aPrefs.rrq_LoStr);
spRR_HiStr.spinner("value",mPref.aPrefs.rrq_HiStr);

// dynamically insert notegroup checkboxes
populateNotegroupsRandRootTab();
// check boxes according to Pref model
ctl_updateRRQprefView();


// get any url parameters and adjust model(s) appropriately
var url_params = get_url_parameters();
var loadFromUrl = function(){
Expand Down Expand Up @@ -1135,12 +1238,56 @@ jQuery(document).ready(function() {


// bind help button to show help dialog
$('#btnHelp').click(function(){
$('#btnHelp').button({
text: false,
icons:
{
primary: "ui-icon-help"
}
}).click(function(){
$( "#helpText" ).html(HELP_TEXT);
$( "#helpText" ).dialog( "open" );
});

// preferences dialog
$(function() {
$( "#prefWin" ).dialog({
autoOpen: false,
modal: true,
//closeOnEscape: false,
//open: function(event, ui) { $(".ui-dialog-titlebar-close", $(this).parent()).hide(); },
buttons:{
'Save and Close':function(){
//save prefs PrefModel and then write cookie
ctl_updatePrefs();

$(this).dialog('close');
}
}
},{
width: 640,
height: 472

},{
dialogClass:".helpInstructions",
});
});

// bind pref button to show preferences dialog
$('#btnPref').button({
text: false,
icons:
{
primary: "ui-icon-gear"
}
}).click(function(){
$( "#prefWin" ).dialog( "open" );
});

// $('#prefWin').bind('dialogclose', function(event) {
// //when dialog is closed, update the Pref model with data in popup form controls
// ctl_updatePrefs();
// });

// set up eraser brush and clear buttons:

Expand Down
22 changes: 20 additions & 2 deletions fretboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ div#fretboard_container
width:1289px;
}
#message {float:right; display: inline; padding-top: 6px;}
#btnHelp {float:right; padding:3px; width: 24px; height: 24px; font-weight:bold; border-radius: 5px; margin-left: 24px; background-color: white; border: #b5b5b5 solid 1px; }

#btnHelp {float:right; width: 16px; height:16px; padding:0; margin-left: 4px; }
#btnPref {float:right; width: 16px; height:16px; padding:0; margin-left: 4px; }
#diagram_title { font-size:25px; font-weight:bold; margin:0 0 0 15px; display:block; padding:4px; border:0; width:auto; float:left; }

div.h_ctrl_cnt{ padding:10px; margin:0px 10px 0px 10px; }
Expand Down Expand Up @@ -125,6 +125,24 @@ input.color_button { width:40px; border-radius: 5px; margin-left: 8px; }
.tabs-nohdr .ui-tabs-anchor{
font-weight:normal;
}

.prefTabs{
font-size: 11px;
}

.prefTabs .pref_hSpan{
margin: 0 16px 0 0;
}

.prefTabs h3 {
margin-bottom: 6px;
}

.prefTabs .RR_scaleOptionsCol{
display:block;
float: left;
margin-right: 12px;
}
/* must be under tabs-nohdr */
div#notegroupsUnabridged {
font-size:12px;
Expand Down
Loading

0 comments on commit 3d50648

Please sign in to comment.