var is_ordinateur = true; var type_instru = []; var is_playing = false; var intervalPlay; type_instru[0] = 'Piano1'; type_instru[1] = 'Piano2'; type_instru[2] = 'Guitare'; type_instru[3] = 'Guitare2'; type_instru[4] = 'Violon'; type_instru[5] = 'Horn'; type_instru[6] = 'Basse'; type_instru[7] = 'Batterie1'; type_instru[8] = 'Batterie2'; type_instru[9] = 'botsong_filigranne'; var tonalite = []; var type = []; tonalite[0] = 'C'; tonalite[1] = 'C#'; tonalite[2] = 'D'; tonalite[3] = 'D#'; tonalite[4] = 'E'; tonalite[5] = 'F'; tonalite[6] = 'F#'; tonalite[7] = 'G'; tonalite[8] = 'G#'; tonalite[9] = 'A'; tonalite[10] = 'A#'; tonalite[11] = 'B'; type[0] = 'M'; type[1] = 'm'; type[2] = 'dim'; type[3] = 'sus2'; type[4] = 'sus4'; type[5] = '7'; var sounds2 = new Array(9); // array to hold the sound for (var i = 0; i < 9; i++) { sounds2[i] = []; } var all_sounds2 = []; // sert à tout mémoriser les sons sur l'entrée de la page web... function get_urL_instru(num_instru, chord) { if (!is_ordinateur) { return; } chord = chord.replace("#", "%23"); chord = chord.replace("dim", "°"); chord = chord.replace("m", "min"); chord = chord.replace("°", "dim"); var src = ''; if (num_instru == 5) { // si l'HORN chord += '.wav'; // on ajoute une extension car on a remixé le volume... } if (num_instru >= 7) { src = "touslesinstruments/mp3/" + type_instru[num_instru] + ".wav.mp3"; } else { src = "touslesinstruments/mp3/" + type_instru[num_instru] + chord + ".wav.mp3"; // set the resource location } return src; } // Initialisation de la variable soundToPlay var soundToPlay = 0; function preload_all_sound_for_chords(chords) { if (!is_ordinateur) { return; } all_sounds2 = []; // Réinitialiser les sons for (var num_instru = 0; num_instru < 9; num_instru++) { for (var i = 0; i < chords.length; i++) { var chord = chords[i]; var sound = new Audio(); // créer l'audio sound.src = get_urL_instru(num_instru, chord); // définir la source all_sounds2.push(sound); // ajouter le son dans le tableau } } } function preload_sound_for_chords(chords) { if (!is_ordinateur) { return; } // Réinitialiser le tableau des sons et chaque instrument sounds2 = new Array(9); for (var i = 0; i < 9; i++) { sounds2[i] = []; // Chaque élément doit être un tableau } for (var num_instru = 0; num_instru < 9; num_instru++) { // Utiliser < 9 ici pour éviter un index hors limites for (var i = 0; i < chords.length; i++) { var url_instru = get_urL_instru(num_instru, chords[i]); var sound = new Audio(url_instru); // Créer un nouvel objet Audio sounds2[num_instru].push(sound); // Ajouter le son dans le tableau } } } function playSoundofInstru(num_instru){ if (!is_ordinateur) { return; } if (!sounds2[num_instru] || !sounds2[num_instru][soundToPlay]) return; // Si pas de sons, on quitte var sound = sounds2[num_instru][soundToPlay]; // Obtenir le son suivant if (sound && !is_playing) { sound.currentTime = 0; // Revenir au début sound.play(); // Jouer } } function stopSoundofInstru(num_instru){ if (!is_ordinateur) { return; } if (!sounds2[num_instru] || !sounds2[num_instru][soundToPlay]) return; // Si pas de sons, on quitte var sound = sounds2[num_instru][soundToPlay]; if (sound) { sound.pause(); // Arrêter la lecture } } function playSound() { if (!is_ordinateur) { return; } for (var i = 0; i < 9; i++) { // Correction de la boucle, commencer à 0 playSoundofInstru(i); // Jouer chaque son pour chaque instrument } if (!intervalPlay) { intervalPlay = setInterval(function(){ soundToPlay += 1; if (soundToPlay >= sounds2[0].length) { stopSound(); } else { playSound(); } }, 2000); } } function stopSound() { if (!is_ordinateur) { return; } for (var i = 0; i < 9; i++) { // Correction de la boucle, commencer à 0 stopSoundofInstru(i); // Arrêter chaque son pour chaque instrument } clearInterval(intervalPlay); soundToPlay = 0; }