<commit_before>
var $board = $("#board");
var $settings = $("#sidebar_form");

var fileMap = {
    0 : "a",
    1 : "b",
    2 : "c",
    3 : "d",
    4 : "e",
    5 : "f",
    6 : "g",
    7 : "h"
};

var fileToNoteMap = {
    "a" : "A",
    "b" : "Bb",
    "c" : "C",
    "d" : "D",
    "e" : "E",
    "f" : "F",
    "g" : "C",
    "h" : "B" 
};

var noteToMidiMap = {
    "C":0,
    "C#":1,
    "D":2,
    "D#":3,
    "E":4,
    "F":5,
    "F#":6,
    "G":7,
    "G#":8,
    "A":9,
    "Bb":10,
    "B":11
};

init_board();
init_sound();
bind_squares();

$settings.on( "change", update_settings);


function update_settings() {
    console.log(event);
    if (event.target.tagName === "SELECT") {
        update_sound_mapping();
    }
}

function update_sound_mapping(){
    var i;
    console.log(fileMap.size);
    for (var k in fileMap) {
        selected_options = $("#file_" + fileMap[k]).find(":selected").text(); // TODO here
        console.log(selected_options);
    }
    //console.log(event.jquery get selec);
}

function bind_squares(){
    $board.on("click", handle_square_click);
}

function handle_square_click() {
    console.log(event.target.id);
    $square = $(event.target);
    highlight_square($square);
    play_square($square);
}

function highlight_square($square){
    //console.log($square);
    $square.addClass("highlight");
    //$square.css("background-color", "#FF6600"); //TODO fix just adding the class
    //console.log($square);
    window.setTimeout(function(){
        $square.removeClass("highlight");
        //$square.css("background-color", "#ffffff");
    }, 500);
}

function play_square($square){
    //console.log($square);
    var delay = 0; // play one note every quarter second
    var note = get_note($square.context.id); // the MIDI note
    var velocity = 127; // how hard the note hits

    MIDI.setVolume(0, 127);
    MIDI.noteOn(0, note, velocity, delay);
    MIDI.noteOff(0, note, delay + 0.75);
}

function get_note(squareId){
    file = squareId[0];
    //noteStr <- some mapping from file to notes
    noteStr = fileToNoteMap[file];
    console.log(noteStr);
    noteNum = get_note_number(noteStr, 4);<commit_msg>Remapping the notes by file works perfectly<commit_after>
var $board = $("#board");
var $settings = $("#sidebar_form");

var fileMap = {
    0 : "a",
    1 : "b",
    2 : "c",
    3 : "d",
    4 : "e",
    5 : "f",
    6 : "g",
    7 : "h"
};

var fileToNoteMap = {
    "a" : "A",
    "b" : "Bb",
    "c" : "C",
    "d" : "D",
    "e" : "E",
    "f" : "F",
    "g" : "G",
    "h" : "B" 
};

var noteToMidiMap = {
    "C":0,
    "C#":1,
    "D":2,
    "D#":3,
    "E":4,
    "F":5,
    "F#":6,
    "G":7,
    "G#":8,
    "A":9,
    "Bb":10,
    "B":11
};

init_board();
init_sound();
bind_squares();

$settings.on( "change", update_settings);


function update_settings() {
    console.log(event);
    if (event.target.tagName === "SELECT") {
        update_sound_mapping();
    }
}

function update_sound_mapping(){
    var i;
    var new_fileToNoteMap = {};
    //console.log(fileMap.size);
    for (var k in fileMap) {
        newNote = $("#file_" + fileMap[k]).find(":selected").text(); // TODO here
        //console.log(newNote);
        new_fileToNoteMap[fileMap[k]] = newNote;
    }
    console.log(new_fileToNoteMap);
    fileToNoteMap = new_fileToNoteMap;
}

function bind_squares(){
    $board.on("click", handle_square_click);
}

function handle_square_click() {
    console.log(event.target.id);
    $square = $(event.target);
    highlight_square($square);
    play_square($square);
}

function highlight_square($square){
    //console.log($square);
    $square.addClass("highlight");
    //$square.css("background-color", "#FF6600"); //TODO fix just adding the class
    //console.log($square);
    window.setTimeout(function(){
        $square.removeClass("highlight");
        //$square.css("background-color", "#ffffff");
    }, 500);
}

function play_square($square){
    //console.log($square);
    var delay = 0; // play one note every quarter second
    var note = get_note($square.context.id); // the MIDI note
    var velocity = 127; // how hard the note hits

    // TODO consider a loading thing...
    MIDI.setVolume(0, 127);
    MIDI.noteOn(0, note, velocity, delay);
    MIDI.noteOff(0, note, delay + 0.75);
}

function get_note(squareId){
    file = squareId[0];
    noteStr = fileToNoteMap[file];
    console.log(noteStr);
    noteNum = get_note_number(noteStr, 4);
{'fraction_non_alphanumeric': 0.19552572706935123, 'fraction_numerical': 0.019686800894854587, 'mean_word_length': 2.7825719120135366, 'pattern_counts': {'":': 26, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '555484', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1651, 'n_words': 349}