Path: blob/main/src/resources/formats/revealjs/plugins/tone/tone.js
12923 views
window.QuartoTone = function () {1return {2id: "quarto-tone",3init: function (deck) {4function slideToneScale(i) {5// https://www.intmath.com/trigonometric-graphs/music.php6const note = 15 - (deck.getTotalSlides() - i);7return 440 * 2 ** (note / 12);8}910/*11* Sliding tones between C3 and C5 with equal steps between tones12* but not aligned to musical scale13*/14function slideToneBounded(i, lower = 261.63, upper = 1046.5) {15const step = (upper - lower) / deck.getTotalSlides();16return lower + step * i;17}1819/*20* Choose slide tone scale automatically based on number of slides.21* If there are <= 32 slides, use musical scale.22*/23function slideToneAuto(toneIdx) {24return deck.getTotalSlides() > 3225? slideToneBounded(toneIdx)26: slideToneScale(toneIdx);27}2829const synth = new Tone.Synth({30oscillator: {31type: "sine",32},33envelope: {34attack: 0.001,35decay: 0.2,36sustain: 0.2,37release: 1,38},39}).toMaster();4041const playTone = () => {42synth.triggerAttackRelease(43slideToneAuto(deck.getSlidePastCount()),44"8n"45);46};47deck.on("slidechanged", playTone);48deck.on("fragmentshown", playTone);49deck.on("fragmenthidden", playTone);50},51};52};535455