├── .github ├── dependabot.yml └── workflows │ └── deploy.yml ├── .gitignore ├── .nvmrc ├── Cargo.lock ├── Cargo.toml ├── LICENSE_APACHE ├── LICENSE_MIT ├── README.md ├── bootstrap.js ├── package-lock.json ├── package.json ├── src ├── app.rs ├── chord.rs ├── font.rs ├── lib.rs ├── score.rs ├── settings.rs └── tpc_octave.rs ├── static ├── .gitignore ├── Bravura.otf ├── Bravura.woff ├── Bravura.woff2 ├── bravura.css ├── favicon.png ├── index.html └── style.scss └── webpack.config.js /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Set update schedule for each package manager 2 | 3 | version: 2 4 | updates: 5 | 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | # Check for updates to GitHub Actions every weekday 10 | interval: "weekly" 11 | 12 | - package-ecosystem: "npm" 13 | directory: "/" 14 | schedule: 15 | # Check for updates to GitHub Actions every weekday 16 | interval: "weekly" 17 | 18 | - package-ecosystem: "cargo" 19 | directory: "/" 20 | schedule: 21 | # Check for updates managed by Composer once a week 22 | interval: "weekly" 23 | 24 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy 2 | on: 3 | push: 4 | branches: 5 | - master 6 | jobs: 7 | build-and-deploy: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 🛎️ 11 | uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. 12 | with: 13 | persist-credentials: false 14 | 15 | - name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built. 16 | run: | 17 | curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh 18 | npm install 19 | npm run build 20 | 21 | - name: Deploy 🚀 22 | uses: JamesIves/github-pages-deploy-action@releases/v3 23 | with: 24 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 25 | BRANCH: gh-pages # The branch the action should deploy to. 26 | FOLDER: dist # The folder the action should deploy. 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | bin/ 4 | pkg/ 5 | dist/ 6 | wasm-pack.log 7 | node_modules 8 | /secrets/ 9 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 13.* 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "anyhow" 5 | version = "1.0.32" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" 8 | 9 | [[package]] 10 | name = "anymap" 11 | version = "0.12.1" 12 | source = "registry+https://github.com/rust-lang/crates.io-index" 13 | checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" 14 | 15 | [[package]] 16 | name = "autocfg" 17 | version = "1.0.0" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" 20 | 21 | [[package]] 22 | name = "bincode" 23 | version = "1.2.1" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "5753e2a71534719bf3f4e57006c3a4f0d2c672a4b676eec84161f763eca87dbf" 26 | dependencies = [ 27 | "byteorder", 28 | "serde", 29 | ] 30 | 31 | [[package]] 32 | name = "boolinator" 33 | version = "2.4.0" 34 | source = "registry+https://github.com/rust-lang/crates.io-index" 35 | checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9" 36 | 37 | [[package]] 38 | name = "bumpalo" 39 | version = "3.4.0" 40 | source = "registry+https://github.com/rust-lang/crates.io-index" 41 | checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" 42 | 43 | [[package]] 44 | name = "byteorder" 45 | version = "1.3.4" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" 48 | 49 | [[package]] 50 | name = "bytes" 51 | version = "0.5.6" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" 54 | 55 | [[package]] 56 | name = "cfg-if" 57 | version = "0.1.10" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 60 | 61 | [[package]] 62 | name = "cfg-match" 63 | version = "0.2.1" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "8100e46ff92eb85bf6dc2930c73f2a4f7176393c84a9446b3d501e1b354e7b34" 66 | 67 | [[package]] 68 | name = "chord-quiz" 69 | version = "0.1.0" 70 | dependencies = [ 71 | "log", 72 | "num-traits", 73 | "rand", 74 | "serde", 75 | "serde_derive", 76 | "tonality", 77 | "wasm-bindgen", 78 | "wasm-bindgen-test", 79 | "wasm-logger", 80 | "web-sys", 81 | "wee_alloc", 82 | "yew", 83 | ] 84 | 85 | [[package]] 86 | name = "console_error_panic_hook" 87 | version = "0.1.6" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" 90 | dependencies = [ 91 | "cfg-if", 92 | "wasm-bindgen", 93 | ] 94 | 95 | [[package]] 96 | name = "fnv" 97 | version = "1.0.7" 98 | source = "registry+https://github.com/rust-lang/crates.io-index" 99 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 100 | 101 | [[package]] 102 | name = "futures" 103 | version = "0.3.5" 104 | source = "registry+https://github.com/rust-lang/crates.io-index" 105 | checksum = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613" 106 | dependencies = [ 107 | "futures-channel", 108 | "futures-core", 109 | "futures-executor", 110 | "futures-io", 111 | "futures-sink", 112 | "futures-task", 113 | "futures-util", 114 | ] 115 | 116 | [[package]] 117 | name = "futures-channel" 118 | version = "0.3.5" 119 | source = "registry+https://github.com/rust-lang/crates.io-index" 120 | checksum = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5" 121 | dependencies = [ 122 | "futures-core", 123 | "futures-sink", 124 | ] 125 | 126 | [[package]] 127 | name = "futures-core" 128 | version = "0.3.5" 129 | source = "registry+https://github.com/rust-lang/crates.io-index" 130 | checksum = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399" 131 | 132 | [[package]] 133 | name = "futures-executor" 134 | version = "0.3.5" 135 | source = "registry+https://github.com/rust-lang/crates.io-index" 136 | checksum = "10d6bb888be1153d3abeb9006b11b02cf5e9b209fda28693c31ae1e4e012e314" 137 | dependencies = [ 138 | "futures-core", 139 | "futures-task", 140 | "futures-util", 141 | ] 142 | 143 | [[package]] 144 | name = "futures-io" 145 | version = "0.3.5" 146 | source = "registry+https://github.com/rust-lang/crates.io-index" 147 | checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" 148 | 149 | [[package]] 150 | name = "futures-macro" 151 | version = "0.3.5" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "d0b5a30a4328ab5473878237c447333c093297bded83a4983d10f4deea240d39" 154 | dependencies = [ 155 | "proc-macro-hack", 156 | "proc-macro2", 157 | "quote", 158 | "syn", 159 | ] 160 | 161 | [[package]] 162 | name = "futures-sink" 163 | version = "0.3.5" 164 | source = "registry+https://github.com/rust-lang/crates.io-index" 165 | checksum = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc" 166 | 167 | [[package]] 168 | name = "futures-task" 169 | version = "0.3.5" 170 | source = "registry+https://github.com/rust-lang/crates.io-index" 171 | checksum = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626" 172 | dependencies = [ 173 | "once_cell", 174 | ] 175 | 176 | [[package]] 177 | name = "futures-util" 178 | version = "0.3.5" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" 181 | dependencies = [ 182 | "futures-channel", 183 | "futures-core", 184 | "futures-io", 185 | "futures-macro", 186 | "futures-sink", 187 | "futures-task", 188 | "memchr", 189 | "pin-project", 190 | "pin-utils", 191 | "proc-macro-hack", 192 | "proc-macro-nested", 193 | "slab", 194 | ] 195 | 196 | [[package]] 197 | name = "getrandom" 198 | version = "0.1.14" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" 201 | dependencies = [ 202 | "cfg-if", 203 | "libc", 204 | "wasi", 205 | "wasm-bindgen", 206 | ] 207 | 208 | [[package]] 209 | name = "gloo" 210 | version = "0.2.1" 211 | source = "registry+https://github.com/rust-lang/crates.io-index" 212 | checksum = "68ce6f2dfa9f57f15b848efa2aade5e1850dc72986b87a2b0752d44ca08f4967" 213 | dependencies = [ 214 | "gloo-console-timer", 215 | "gloo-events", 216 | "gloo-file", 217 | "gloo-timers", 218 | ] 219 | 220 | [[package]] 221 | name = "gloo-console-timer" 222 | version = "0.1.0" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | checksum = "b48675544b29ac03402c6dffc31a912f716e38d19f7e74b78b7e900ec3c941ea" 225 | dependencies = [ 226 | "web-sys", 227 | ] 228 | 229 | [[package]] 230 | name = "gloo-events" 231 | version = "0.1.1" 232 | source = "registry+https://github.com/rust-lang/crates.io-index" 233 | checksum = "088514ec8ef284891c762c88a66b639b3a730134714692ee31829765c5bc814f" 234 | dependencies = [ 235 | "wasm-bindgen", 236 | "web-sys", 237 | ] 238 | 239 | [[package]] 240 | name = "gloo-file" 241 | version = "0.1.0" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | checksum = "8f9fecfe46b5dc3cc46f58e98ba580cc714f2c93860796d002eb3527a465ef49" 244 | dependencies = [ 245 | "gloo-events", 246 | "js-sys", 247 | "wasm-bindgen", 248 | "web-sys", 249 | ] 250 | 251 | [[package]] 252 | name = "gloo-timers" 253 | version = "0.2.1" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" 256 | dependencies = [ 257 | "js-sys", 258 | "wasm-bindgen", 259 | "web-sys", 260 | ] 261 | 262 | [[package]] 263 | name = "hashbrown" 264 | version = "0.8.1" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" 267 | dependencies = [ 268 | "autocfg", 269 | ] 270 | 271 | [[package]] 272 | name = "http" 273 | version = "0.2.1" 274 | source = "registry+https://github.com/rust-lang/crates.io-index" 275 | checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" 276 | dependencies = [ 277 | "bytes", 278 | "fnv", 279 | "itoa", 280 | ] 281 | 282 | [[package]] 283 | name = "indexmap" 284 | version = "1.5.0" 285 | source = "registry+https://github.com/rust-lang/crates.io-index" 286 | checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" 287 | dependencies = [ 288 | "autocfg", 289 | "hashbrown", 290 | ] 291 | 292 | [[package]] 293 | name = "itoa" 294 | version = "0.4.6" 295 | source = "registry+https://github.com/rust-lang/crates.io-index" 296 | checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" 297 | 298 | [[package]] 299 | name = "js-sys" 300 | version = "0.3.42" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2" 303 | dependencies = [ 304 | "wasm-bindgen", 305 | ] 306 | 307 | [[package]] 308 | name = "lazy_static" 309 | version = "1.4.0" 310 | source = "registry+https://github.com/rust-lang/crates.io-index" 311 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 312 | 313 | [[package]] 314 | name = "libc" 315 | version = "0.2.73" 316 | source = "registry+https://github.com/rust-lang/crates.io-index" 317 | checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" 318 | 319 | [[package]] 320 | name = "log" 321 | version = "0.4.11" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" 324 | dependencies = [ 325 | "cfg-if", 326 | ] 327 | 328 | [[package]] 329 | name = "memchr" 330 | version = "2.3.3" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" 333 | 334 | [[package]] 335 | name = "memory_units" 336 | version = "0.4.0" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" 339 | 340 | [[package]] 341 | name = "num-derive" 342 | version = "0.3.0" 343 | source = "registry+https://github.com/rust-lang/crates.io-index" 344 | checksum = "0c8b15b261814f992e33760b1fca9fe8b693d8a65299f20c9901688636cfb746" 345 | dependencies = [ 346 | "proc-macro2", 347 | "quote", 348 | "syn", 349 | ] 350 | 351 | [[package]] 352 | name = "num-traits" 353 | version = "0.2.12" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" 356 | dependencies = [ 357 | "autocfg", 358 | ] 359 | 360 | [[package]] 361 | name = "once_cell" 362 | version = "1.4.0" 363 | source = "registry+https://github.com/rust-lang/crates.io-index" 364 | checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" 365 | 366 | [[package]] 367 | name = "pin-project" 368 | version = "0.4.22" 369 | source = "registry+https://github.com/rust-lang/crates.io-index" 370 | checksum = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17" 371 | dependencies = [ 372 | "pin-project-internal", 373 | ] 374 | 375 | [[package]] 376 | name = "pin-project-internal" 377 | version = "0.4.22" 378 | source = "registry+https://github.com/rust-lang/crates.io-index" 379 | checksum = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7" 380 | dependencies = [ 381 | "proc-macro2", 382 | "quote", 383 | "syn", 384 | ] 385 | 386 | [[package]] 387 | name = "pin-utils" 388 | version = "0.1.0" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 391 | 392 | [[package]] 393 | name = "ppv-lite86" 394 | version = "0.2.8" 395 | source = "registry+https://github.com/rust-lang/crates.io-index" 396 | checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea" 397 | 398 | [[package]] 399 | name = "proc-macro-hack" 400 | version = "0.5.18" 401 | source = "registry+https://github.com/rust-lang/crates.io-index" 402 | checksum = "99c605b9a0adc77b7211c6b1f722dcb613d68d66859a44f3d485a6da332b0598" 403 | 404 | [[package]] 405 | name = "proc-macro-nested" 406 | version = "0.1.6" 407 | source = "registry+https://github.com/rust-lang/crates.io-index" 408 | checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" 409 | 410 | [[package]] 411 | name = "proc-macro2" 412 | version = "1.0.19" 413 | source = "registry+https://github.com/rust-lang/crates.io-index" 414 | checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" 415 | dependencies = [ 416 | "unicode-xid", 417 | ] 418 | 419 | [[package]] 420 | name = "quote" 421 | version = "1.0.7" 422 | source = "registry+https://github.com/rust-lang/crates.io-index" 423 | checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" 424 | dependencies = [ 425 | "proc-macro2", 426 | ] 427 | 428 | [[package]] 429 | name = "rand" 430 | version = "0.7.3" 431 | source = "registry+https://github.com/rust-lang/crates.io-index" 432 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" 433 | dependencies = [ 434 | "getrandom", 435 | "libc", 436 | "rand_chacha", 437 | "rand_core", 438 | "rand_hc", 439 | ] 440 | 441 | [[package]] 442 | name = "rand_chacha" 443 | version = "0.2.2" 444 | source = "registry+https://github.com/rust-lang/crates.io-index" 445 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" 446 | dependencies = [ 447 | "ppv-lite86", 448 | "rand_core", 449 | ] 450 | 451 | [[package]] 452 | name = "rand_core" 453 | version = "0.5.1" 454 | source = "registry+https://github.com/rust-lang/crates.io-index" 455 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 456 | dependencies = [ 457 | "getrandom", 458 | ] 459 | 460 | [[package]] 461 | name = "rand_hc" 462 | version = "0.2.0" 463 | source = "registry+https://github.com/rust-lang/crates.io-index" 464 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 465 | dependencies = [ 466 | "rand_core", 467 | ] 468 | 469 | [[package]] 470 | name = "ryu" 471 | version = "1.0.5" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 474 | 475 | [[package]] 476 | name = "scoped-tls" 477 | version = "1.0.0" 478 | source = "registry+https://github.com/rust-lang/crates.io-index" 479 | checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" 480 | 481 | [[package]] 482 | name = "serde" 483 | version = "1.0.114" 484 | source = "registry+https://github.com/rust-lang/crates.io-index" 485 | checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" 486 | dependencies = [ 487 | "serde_derive", 488 | ] 489 | 490 | [[package]] 491 | name = "serde_derive" 492 | version = "1.0.114" 493 | source = "registry+https://github.com/rust-lang/crates.io-index" 494 | checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" 495 | dependencies = [ 496 | "proc-macro2", 497 | "quote", 498 | "syn", 499 | ] 500 | 501 | [[package]] 502 | name = "serde_json" 503 | version = "1.0.56" 504 | source = "registry+https://github.com/rust-lang/crates.io-index" 505 | checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" 506 | dependencies = [ 507 | "itoa", 508 | "ryu", 509 | "serde", 510 | ] 511 | 512 | [[package]] 513 | name = "slab" 514 | version = "0.4.2" 515 | source = "registry+https://github.com/rust-lang/crates.io-index" 516 | checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" 517 | 518 | [[package]] 519 | name = "syn" 520 | version = "1.0.35" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" 523 | dependencies = [ 524 | "proc-macro2", 525 | "quote", 526 | "unicode-xid", 527 | ] 528 | 529 | [[package]] 530 | name = "thiserror" 531 | version = "1.0.20" 532 | source = "registry+https://github.com/rust-lang/crates.io-index" 533 | checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" 534 | dependencies = [ 535 | "thiserror-impl", 536 | ] 537 | 538 | [[package]] 539 | name = "thiserror-impl" 540 | version = "1.0.20" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" 543 | dependencies = [ 544 | "proc-macro2", 545 | "quote", 546 | "syn", 547 | ] 548 | 549 | [[package]] 550 | name = "tonality" 551 | version = "0.1.1" 552 | source = "registry+https://github.com/rust-lang/crates.io-index" 553 | checksum = "88e807dd0d596d33c430311d07ca85b4460441adc448d6db20973f749c77e7d8" 554 | dependencies = [ 555 | "num-derive", 556 | "num-traits", 557 | ] 558 | 559 | [[package]] 560 | name = "unicode-xid" 561 | version = "0.2.1" 562 | source = "registry+https://github.com/rust-lang/crates.io-index" 563 | checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" 564 | 565 | [[package]] 566 | name = "wasi" 567 | version = "0.9.0+wasi-snapshot-preview1" 568 | source = "registry+https://github.com/rust-lang/crates.io-index" 569 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" 570 | 571 | [[package]] 572 | name = "wasm-bindgen" 573 | version = "0.2.65" 574 | source = "registry+https://github.com/rust-lang/crates.io-index" 575 | checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d" 576 | dependencies = [ 577 | "cfg-if", 578 | "wasm-bindgen-macro", 579 | ] 580 | 581 | [[package]] 582 | name = "wasm-bindgen-backend" 583 | version = "0.2.65" 584 | source = "registry+https://github.com/rust-lang/crates.io-index" 585 | checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d" 586 | dependencies = [ 587 | "bumpalo", 588 | "lazy_static", 589 | "log", 590 | "proc-macro2", 591 | "quote", 592 | "syn", 593 | "wasm-bindgen-shared", 594 | ] 595 | 596 | [[package]] 597 | name = "wasm-bindgen-futures" 598 | version = "0.4.15" 599 | source = "registry+https://github.com/rust-lang/crates.io-index" 600 | checksum = "41ad6e4e8b2b7f8c90b6e09a9b590ea15cb0d1dbe28502b5a405cd95d1981671" 601 | dependencies = [ 602 | "cfg-if", 603 | "js-sys", 604 | "wasm-bindgen", 605 | "web-sys", 606 | ] 607 | 608 | [[package]] 609 | name = "wasm-bindgen-macro" 610 | version = "0.2.65" 611 | source = "registry+https://github.com/rust-lang/crates.io-index" 612 | checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e" 613 | dependencies = [ 614 | "quote", 615 | "wasm-bindgen-macro-support", 616 | ] 617 | 618 | [[package]] 619 | name = "wasm-bindgen-macro-support" 620 | version = "0.2.65" 621 | source = "registry+https://github.com/rust-lang/crates.io-index" 622 | checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6" 623 | dependencies = [ 624 | "proc-macro2", 625 | "quote", 626 | "syn", 627 | "wasm-bindgen-backend", 628 | "wasm-bindgen-shared", 629 | ] 630 | 631 | [[package]] 632 | name = "wasm-bindgen-shared" 633 | version = "0.2.65" 634 | source = "registry+https://github.com/rust-lang/crates.io-index" 635 | checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87" 636 | 637 | [[package]] 638 | name = "wasm-bindgen-test" 639 | version = "0.3.15" 640 | source = "registry+https://github.com/rust-lang/crates.io-index" 641 | checksum = "ab74fdf3a6bc3ae5b47bc1208c8c4eebc8efbd8025dda808d0e4819bfd3d39c4" 642 | dependencies = [ 643 | "console_error_panic_hook", 644 | "js-sys", 645 | "scoped-tls", 646 | "wasm-bindgen", 647 | "wasm-bindgen-futures", 648 | "wasm-bindgen-test-macro", 649 | ] 650 | 651 | [[package]] 652 | name = "wasm-bindgen-test-macro" 653 | version = "0.3.15" 654 | source = "registry+https://github.com/rust-lang/crates.io-index" 655 | checksum = "3a2bf1109ffaa2554e2e7caa1bb301f0496aaf1ecb50f81df5e7291f5cc98f2f" 656 | dependencies = [ 657 | "proc-macro2", 658 | "quote", 659 | ] 660 | 661 | [[package]] 662 | name = "wasm-logger" 663 | version = "0.2.0" 664 | source = "registry+https://github.com/rust-lang/crates.io-index" 665 | checksum = "074649a66bb306c8f2068c9016395fa65d8e08d2affcbf95acf3c24c3ab19718" 666 | dependencies = [ 667 | "log", 668 | "wasm-bindgen", 669 | "web-sys", 670 | ] 671 | 672 | [[package]] 673 | name = "web-sys" 674 | version = "0.3.42" 675 | source = "registry+https://github.com/rust-lang/crates.io-index" 676 | checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2" 677 | dependencies = [ 678 | "js-sys", 679 | "wasm-bindgen", 680 | ] 681 | 682 | [[package]] 683 | name = "wee_alloc" 684 | version = "0.4.5" 685 | source = "registry+https://github.com/rust-lang/crates.io-index" 686 | checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" 687 | dependencies = [ 688 | "cfg-if", 689 | "libc", 690 | "memory_units", 691 | "winapi", 692 | ] 693 | 694 | [[package]] 695 | name = "winapi" 696 | version = "0.3.9" 697 | source = "registry+https://github.com/rust-lang/crates.io-index" 698 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 699 | dependencies = [ 700 | "winapi-i686-pc-windows-gnu", 701 | "winapi-x86_64-pc-windows-gnu", 702 | ] 703 | 704 | [[package]] 705 | name = "winapi-i686-pc-windows-gnu" 706 | version = "0.4.0" 707 | source = "registry+https://github.com/rust-lang/crates.io-index" 708 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 709 | 710 | [[package]] 711 | name = "winapi-x86_64-pc-windows-gnu" 712 | version = "0.4.0" 713 | source = "registry+https://github.com/rust-lang/crates.io-index" 714 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 715 | 716 | [[package]] 717 | name = "yew" 718 | version = "0.16.2" 719 | source = "registry+https://github.com/rust-lang/crates.io-index" 720 | checksum = "fc1e1b60b090bf29758c6c42da2d2d6d54aa97dc73e3ccd1cd99d664b4c754cf" 721 | dependencies = [ 722 | "anyhow", 723 | "anymap", 724 | "bincode", 725 | "cfg-if", 726 | "cfg-match", 727 | "console_error_panic_hook", 728 | "futures", 729 | "gloo", 730 | "http", 731 | "indexmap", 732 | "js-sys", 733 | "log", 734 | "proc-macro-hack", 735 | "proc-macro-nested", 736 | "ryu", 737 | "serde", 738 | "serde_json", 739 | "slab", 740 | "thiserror", 741 | "wasm-bindgen", 742 | "wasm-bindgen-futures", 743 | "web-sys", 744 | "yew-macro", 745 | ] 746 | 747 | [[package]] 748 | name = "yew-macro" 749 | version = "0.16.1" 750 | source = "registry+https://github.com/rust-lang/crates.io-index" 751 | checksum = "f1d2fe46d7922ecd99af4e5b4eddcab58c70ec741e31de6e1b910d5873a3095f" 752 | dependencies = [ 753 | "boolinator", 754 | "lazy_static", 755 | "proc-macro-hack", 756 | "proc-macro2", 757 | "quote", 758 | "syn", 759 | ] 760 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "chord-quiz" 3 | version = "0.1.0" 4 | authors = ["Stig Johan Berggren "] 5 | edition = "2018" 6 | 7 | [lib] 8 | crate-type = ["cdylib", "rlib"] 9 | 10 | [dependencies] 11 | log = "0.4.8" 12 | num-traits = "0.2.11" 13 | rand = { version = "0.7.3", features = ["wasm-bindgen"] } 14 | serde = "1.0.110" 15 | serde_derive = "1.0.110" 16 | tonality = "0.1.1" 17 | wasm-bindgen = "0.2.62" 18 | wasm-logger = "0.2.0" 19 | wee_alloc = "0.4.5" 20 | yew = "0.16.2" 21 | web-sys = "0.3.39" 22 | 23 | [dev-dependencies] 24 | wasm-bindgen-test = "0.3.12" 25 | 26 | [profile.release] 27 | panic = 'abort' 28 | opt-level = 'z' 29 | lto = true 30 | -------------------------------------------------------------------------------- /LICENSE_APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 {{authors}} 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chord Quiz 2 | 3 | A web app that can generate music theory practice questions. 4 | 5 | Written in [Rust](https://rust-lang.org) using the [Yew framework](https://yew.rs). 6 | 7 | The music font is Bravura . 8 | -------------------------------------------------------------------------------- /bootstrap.js: -------------------------------------------------------------------------------- 1 | import './static/style.scss'; 2 | 3 | import("./pkg").then(module => { 4 | module.run_app(); 5 | }); 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "test": "echo \"Error: no test specified\" && exit 1", 5 | "dev": "webpack --mode development", 6 | "build": "webpack --mode production", 7 | "start:dev": "webpack-dev-server --mode development" 8 | }, 9 | "devDependencies": { 10 | "@wasm-tool/wasm-pack-plugin": "^1.1.0", 11 | "copy-webpack-plugin": "^6.0.3", 12 | "css-loader": "^3.6.0", 13 | "sass": "^1.26.9", 14 | "sass-loader": "^9.0.1", 15 | "style-loader": "^1.2.1", 16 | "wasm-pack": "^0.9.1", 17 | "webpack": "^4.42.0", 18 | "webpack-cli": "^3.3.12", 19 | "webpack-dev-server": "^3.10.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app.rs: -------------------------------------------------------------------------------- 1 | use num_traits::FromPrimitive; 2 | use rand::Rng; 3 | use tonality::Tpc; 4 | use yew::prelude::*; 5 | 6 | use crate::chord::{Chord, Kind}; 7 | use crate::settings::Settings; 8 | use crate::tpc_octave::TpcOctave; 9 | 10 | pub struct App { 11 | link: ComponentLink, 12 | chord: Chord, 13 | revealed: bool, 14 | num_chords: usize, 15 | num_correct: usize, 16 | use_dbl_accidentals: bool, 17 | } 18 | 19 | pub enum Msg { 20 | Reveal, 21 | NextCorrect, 22 | NextWrong, 23 | ToggleDblAccidentals, 24 | } 25 | 26 | fn root_range(chord: &Kind, use_dbl_accidentals: bool) -> (isize, isize) { 27 | if use_dbl_accidentals { 28 | ( 29 | chord.flattest_root() as isize, 30 | chord.sharpest_root() as isize, 31 | ) 32 | } else { 33 | ( 34 | chord.flattest_root_no_dbl_flat() as isize, 35 | chord.sharpest_root_no_dbl_sharp() as isize, 36 | ) 37 | } 38 | } 39 | 40 | fn random_chord(use_dbl_accidentals: bool) -> Chord { 41 | let mut rng = rand::thread_rng(); 42 | 43 | let chord = match rng.gen_range(0, 9) { 44 | 0 => Kind::Maj, 45 | 1 => Kind::Min, 46 | 2 => Kind::Dim, 47 | 3 => Kind::Aug, 48 | 4 => Kind::Dom7, 49 | 5 => Kind::Dim7, 50 | 6 => Kind::Maj7, 51 | 7 => Kind::Min7, 52 | _ => Kind::Min7b5, 53 | }; 54 | 55 | let (tpc_low, tpc_high) = root_range(&chord, use_dbl_accidentals); 56 | 57 | let tpc_num = rng.gen_range(tpc_low, tpc_high); 58 | let tpc: Tpc = FromPrimitive::from_isize(tpc_num).unwrap(); 59 | let octave = rng.gen_range(2, 5); 60 | let root = TpcOctave(tpc, octave); 61 | Chord::new(root.clone(), chord.clone()) 62 | .unwrap_or_else(|| panic!("Out of range with {:?}, {:?}", root, chord)) 63 | } 64 | 65 | impl Component for App { 66 | type Message = Msg; 67 | type Properties = (); 68 | 69 | fn create(_: Self::Properties, link: ComponentLink) -> Self { 70 | let chord = random_chord(false); 71 | let revealed = false; 72 | Self { 73 | link, 74 | chord, 75 | revealed, 76 | num_chords: 0, 77 | num_correct: 0, 78 | use_dbl_accidentals: false, 79 | } 80 | } 81 | 82 | fn change(&mut self, _props: Self::Properties) -> ShouldRender { 83 | false 84 | } 85 | 86 | fn update(&mut self, msg: Self::Message) -> ShouldRender { 87 | match msg { 88 | Msg::Reveal => self.revealed = true, 89 | Msg::NextCorrect => { 90 | self.num_correct += 1; 91 | self.num_chords += 1; 92 | self.chord = random_chord(self.use_dbl_accidentals); 93 | self.revealed = false 94 | } 95 | Msg::NextWrong => { 96 | self.num_chords += 1; 97 | self.chord = random_chord(self.use_dbl_accidentals); 98 | self.revealed = false 99 | } 100 | Msg::ToggleDblAccidentals => self.use_dbl_accidentals = !self.use_dbl_accidentals, 101 | } 102 | true 103 | } 104 | 105 | fn view(&self) -> Html { 106 | let answer = if self.revealed { 107 | self.chord.to_string() 108 | } else { 109 | String::new() 110 | }; 111 | let button = if self.revealed { 112 | let on_correct = self.link.callback(|_| Msg::NextCorrect); 113 | let on_wrong = self.link.callback(|_| Msg::NextWrong); 114 | html! { 115 |
116 | 117 | 118 |
119 | } 120 | } else { 121 | let on_reveal = self.link.callback(|_| Msg::Reveal); 122 | html! { 123 | 124 | } 125 | }; 126 | let on_toggle = self.link.callback(|_| Msg::ToggleDblAccidentals); 127 | let score = format!("{} out of {} correct", self.num_correct, self.num_chords); 128 | html! { 129 | <> 130 |
131 |

{ "Identify the chord" }

132 |

{ score }

133 |
{ self.chord.to_svg() }
134 |
{ answer }
135 | { button } 136 | 137 |
138 |
139 |
140 | { "The graphics are generated in your browser as an SVG using Steinberg's Bravura musical font. " } 141 | { "The app is programmed in Rust using the Yew framework. " } 142 | { "Repository: "} 143 | { "stigjb/chord-quiz" } 144 |
145 |
146 | 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/chord.rs: -------------------------------------------------------------------------------- 1 | use std::fmt; 2 | 3 | use tonality::{Accidental, Interval, Step, Tpc}; 4 | use yew::Html; 5 | 6 | use crate::score; 7 | use crate::score::StaffPosition; 8 | use crate::tpc_octave::TpcOctave; 9 | 10 | const G_CLEF: char = '\u{e050}'; 11 | const F_CLEF: char = '\u{e062}'; 12 | 13 | #[derive(Clone, Debug, PartialEq)] 14 | pub struct Chord { 15 | root: TpcOctave, 16 | kind: Kind, 17 | tpcs: Vec, 18 | } 19 | 20 | impl Chord { 21 | pub fn new(root: TpcOctave, kind: Kind) -> Option { 22 | kind.with_root(&root).map(|tpcs| Self { root, kind, tpcs }) 23 | } 24 | 25 | pub fn to_svg(&self) -> Html { 26 | let clef = 27 | if self.root.1 >= 4 || (self.root.1 >= 3 && self.root.0.step() as i8 > Step::E as i8) { 28 | Clef::G 29 | } else { 30 | Clef::F 31 | }; 32 | score::Builder::new() 33 | .space(0.5) 34 | .clef(&clef) 35 | .space(6.) 36 | .accidentals(&self.accidentals(&clef)) 37 | .space(1.5) 38 | .chord(&self.staff_positions(&clef)) 39 | .space(6.) 40 | .barline() 41 | .into_svg() 42 | } 43 | 44 | pub fn staff_positions(&self, clef: &Clef) -> Vec { 45 | let root_position = clef.position(&self.tpcs[0]); 46 | self.tpcs 47 | .iter() 48 | .map(|tpc| { 49 | let mut pos = clef.position(tpc); 50 | while pos < root_position { 51 | pos = &pos + 7; 52 | } 53 | pos 54 | }) 55 | .collect() 56 | } 57 | 58 | fn accidentals(&self, clef: &Clef) -> Vec<(Accidental, StaffPosition)> { 59 | self.tpcs 60 | .iter() 61 | .zip(self.staff_positions(&clef)) 62 | .filter_map(|(t, p)| match t.0.altered_step(None) { 63 | (_, Some(acc)) => Some((acc, p)), 64 | (_, None) => None, 65 | }) 66 | .collect() 67 | } 68 | } 69 | 70 | impl Default for Chord { 71 | fn default() -> Self { 72 | let root = TpcOctave(Tpc::C, 4); 73 | Self::new(root, Kind::Maj).unwrap() 74 | } 75 | } 76 | 77 | #[derive(Clone, Debug, PartialEq)] 78 | pub enum Clef { 79 | G, // Bottom staff line E4 80 | C, // Bottom staff line F3 81 | F, // Bottom staff line G2 82 | } 83 | 84 | impl Clef { 85 | fn bottom_staff_position(&self) -> (Step, i8) { 86 | match self { 87 | Self::G => (Step::E, 4), 88 | Self::C => (Step::F, 3), 89 | Self::F => (Step::G, 2), 90 | } 91 | } 92 | 93 | pub fn to_glyph(&self) -> char { 94 | match self { 95 | Self::G => G_CLEF, 96 | Self::C => '@', 97 | Self::F => F_CLEF, 98 | } 99 | } 100 | 101 | pub fn position(&self, tpc_octave: &TpcOctave) -> StaffPosition { 102 | let step = tpc_octave.0.step(); 103 | let (bottom_step, bottom_octave) = self.bottom_staff_position(); 104 | let step_delta = step as i32 - bottom_step as i32; 105 | let octave_delta = 7 * (tpc_octave.1 - bottom_octave); 106 | StaffPosition::new(step_delta + octave_delta as i32) 107 | } 108 | } 109 | 110 | impl fmt::Display for Chord { 111 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 112 | let (step, alter) = self.root.0.altered_step(None); 113 | let alter = alter 114 | .map_or("", |acc| match acc { 115 | Accidental::DblFlat => "♭♭", 116 | Accidental::Flat => "♭", 117 | Accidental::Natural => "", 118 | Accidental::Sharp => "♯", 119 | Accidental::DblSharp => "♯♯", 120 | }); 121 | let kind = match self.kind { 122 | Kind::Aug => "+", 123 | Kind::Maj => "", 124 | Kind::Min => "m", 125 | Kind::Dim => "m♭5", 126 | Kind::Maj7 => "maj7", 127 | Kind::Min7 => "m7", 128 | Kind::Dom7 => "7", 129 | Kind::Dim7 => "dim7", 130 | Kind::Min7b5 => "m7♭5", 131 | }; 132 | write!(f, "{:?}{}{}", step, alter, kind) 133 | } 134 | } 135 | 136 | #[derive(Clone, Debug, PartialEq)] 137 | pub enum Kind { 138 | Maj, 139 | Min, 140 | Dim, 141 | Aug, 142 | Dom7, 143 | Maj7, 144 | Min7, 145 | Min7b5, 146 | Dim7, 147 | } 148 | 149 | impl Kind { 150 | #[allow(clippy::enum_glob_use)] 151 | pub fn intervals(&self) -> Vec { 152 | use Interval::*; 153 | match self { 154 | Self::Maj => vec![Unison, Maj3, P5], 155 | Self::Min => vec![Unison, Min3, P5], 156 | Self::Dim => vec![Unison, Min3, Dim5], 157 | Self::Aug => vec![Unison, Maj3, Aug5], 158 | Self::Dom7 => vec![Unison, Maj3, P5, Min7], 159 | Self::Maj7 => vec![Unison, Maj3, P5, Maj7], 160 | Self::Min7 => vec![Unison, Min3, P5, Min7], 161 | Self::Min7b5 => vec![Unison, Min3, Dim5, Min7], 162 | Self::Dim7 => vec![Unison, Min3, Dim5, Dim7], 163 | } 164 | } 165 | 166 | pub fn with_root(&self, root: &TpcOctave) -> Option> { 167 | self.intervals() 168 | .iter() 169 | .map(|&interval| root.clone() + interval) 170 | .collect() 171 | } 172 | 173 | pub fn flattest_root(&self) -> Tpc { 174 | let flattest_interval = *self.intervals().iter().min().unwrap(); 175 | (Tpc::Fbb - flattest_interval).unwrap().max(Tpc::Fb) 176 | } 177 | 178 | pub fn flattest_root_no_dbl_flat(&self) -> Tpc { 179 | let flattest_interval = *self.intervals().iter().min().unwrap(); 180 | (Tpc::Fb - flattest_interval).unwrap().max(Tpc::Fb) 181 | } 182 | 183 | pub fn sharpest_root(&self) -> Tpc { 184 | let sharpest_interval = *self.intervals().iter().max().unwrap(); 185 | (Tpc::Bss - sharpest_interval).unwrap().min(Tpc::Bs) 186 | } 187 | 188 | pub fn sharpest_root_no_dbl_sharp(&self) -> Tpc { 189 | let sharpest_interval = *self.intervals().iter().max().unwrap(); 190 | (Tpc::Bs - sharpest_interval).unwrap().min(Tpc::Bs) 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/font.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | use std::collections::HashMap; 3 | 4 | #[derive(Deserialize)] 5 | #[serde(rename_all = "camelCase")] 6 | pub struct Metadata { 7 | font_name: String, 8 | font_version: String, 9 | engraving_defaults: HashMap, 10 | } 11 | 12 | #[derive(Deserialize, Debug)] 13 | #[serde(rename_all = "camelCase")] 14 | pub struct BBox { 15 | b_box_n_e: (f32, f32), 16 | b_box_s_w: (f32, f32), 17 | } 18 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![recursion_limit = "512"] 2 | #![warn(clippy::pedantic)] 3 | #![allow(clippy::cast_lossless, clippy::non_ascii_literal)] 4 | 5 | mod app; 6 | mod chord; 7 | mod score; 8 | mod settings; 9 | mod tpc_octave; 10 | 11 | use wasm_bindgen::prelude::*; 12 | 13 | // Use `wee_alloc` as the global allocator. 14 | #[global_allocator] 15 | static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; 16 | 17 | /// Entry point for the web app 18 | #[wasm_bindgen] 19 | pub fn run_app() { 20 | wasm_logger::init(wasm_logger::Config::default()); 21 | yew::start_app::(); 22 | } 23 | -------------------------------------------------------------------------------- /src/score.rs: -------------------------------------------------------------------------------- 1 | use tonality::Accidental; 2 | use yew::{html, Html}; 3 | 4 | use crate::chord; 5 | 6 | // With font-size 16 7 | const STAFF_SPACE: f32 = 4.; 8 | const STAFF_LINE_THICKNESS: f32 = 0.13 * STAFF_SPACE; 9 | const LEGER_LINE_THICKNESS: f32 = 0.16 * STAFF_SPACE; 10 | const THIN_BARLINE_THICKNESS: f32 = 0.16 * STAFF_SPACE; 11 | const BARLINE_SEPARATION: f32 = 0.4 * STAFF_SPACE; 12 | 13 | const NOTEHEAD_WHOLE: char = '\u{e0a2}'; 14 | const ACCIDENTAL_FLAT: char = '\u{e260}'; 15 | const ACCIDENTAL_NATURAL: char = '\u{e261}'; 16 | const ACCIDENTAL_SHARP: char = '\u{e262}'; 17 | const ACCIDENTAL_DOUBLE_SHARP: char = '\u{e263}'; 18 | const ACCIDENTAL_DOUBLE_FLAT: char = '\u{e264}'; 19 | 20 | fn accidental_glyph(acc: Accidental) -> char { 21 | match acc { 22 | Accidental::DblFlat => ACCIDENTAL_DOUBLE_FLAT, 23 | Accidental::Flat => ACCIDENTAL_FLAT, 24 | Accidental::Natural => ACCIDENTAL_NATURAL, 25 | Accidental::Sharp => ACCIDENTAL_SHARP, 26 | Accidental::DblSharp => ACCIDENTAL_DOUBLE_SHARP, 27 | } 28 | } 29 | 30 | pub struct Builder { 31 | cursor: f32, 32 | nodes: Vec, 33 | } 34 | 35 | impl Builder { 36 | pub fn new() -> Self { 37 | Self { 38 | cursor: 0., 39 | nodes: Vec::new(), 40 | } 41 | } 42 | 43 | pub fn space(mut self, size: f32) -> Self { 44 | self.cursor += size * STAFF_SPACE; 45 | self 46 | } 47 | 48 | pub fn clef(mut self, clef: &chord::Clef) -> Self { 49 | use chord::Clef; 50 | let y = match clef { 51 | Clef::G => STAFF_SPACE * 3., 52 | Clef::F => STAFF_SPACE, 53 | Clef::C => STAFF_SPACE * 2., 54 | }; 55 | let clef = html! { { clef.to_glyph() } }; 56 | self.nodes.push(clef); 57 | self 58 | } 59 | 60 | pub fn accidentals(mut self, accs: &[(Accidental, StaffPosition)]) -> Self { 61 | let mut sorted_accs: Vec<_> = accs.to_owned(); 62 | sorted_accs.sort_unstable_by_key(|(_, pos)| -pos.0); 63 | let indents = align_accidentals(&sorted_accs); 64 | let max_indent = indents 65 | .iter() 66 | .min_by(|&a, &b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)) 67 | .unwrap_or(&0.); 68 | self.cursor -= max_indent; 69 | let accidentals = sorted_accs 70 | .iter() 71 | .zip(indents) 72 | .map(|((acc, pos), indent)| { 73 | let glyph = accidental_glyph(*acc); 74 | let y = pos.to_y(); 75 | html! { { glyph } } 76 | }) 77 | .collect::(); 78 | self.nodes.push(accidentals); 79 | self 80 | } 81 | 82 | pub fn barline(mut self) -> Self { 83 | let d = format!( 84 | "M{},0 v16 M{},0 v16", 85 | self.cursor, 86 | self.cursor + BARLINE_SEPARATION 87 | ); 88 | let barline = html! { }; 89 | self.nodes.push(barline); 90 | self.cursor += BARLINE_SEPARATION + 0.5 * THIN_BARLINE_THICKNESS; 91 | self 92 | } 93 | 94 | pub fn chord(mut self, staff_positions: &[StaffPosition]) -> Self { 95 | let bottom_pos: &StaffPosition = staff_positions.iter().min().unwrap(); 96 | let top_pos: &StaffPosition = staff_positions.iter().max().unwrap(); 97 | let lowest_leger = bottom_pos.0 - bottom_pos.0 % 2; 98 | 99 | // Even valued positions <= -2 and >= 10 are candidates for leger lines 100 | let leger_positions = (lowest_leger..=-2) 101 | .step_by(2) 102 | .chain((10..=top_pos.0).step_by(2)); 103 | let legers = leger_positions.map(|l| { 104 | let d = format!("M{},{} h8.752", self.cursor - 1., StaffPosition(l).to_y()); 105 | html! { } 106 | }); 107 | 108 | // Create a note at each position 109 | let notes = staff_positions.iter().map(|i| note(self.cursor, i)); 110 | let triad = html! { 111 | 112 | { for legers } 113 | { for notes } 114 | 115 | }; 116 | self.nodes.push(triad); 117 | self 118 | } 119 | 120 | pub fn into_svg(self) -> Html { 121 | let view_box = format!("-8 -16 {} 48", self.cursor + 16.); 122 | let staff = staff(self.cursor); 123 | html! { 124 | 125 | { staff } 126 | { for self.nodes } 127 | 128 | } 129 | } 130 | } 131 | 132 | fn staff(width: f32) -> Html { 133 | let d = format!( 134 | "M0,0 h{w} M0,4 h{w} M0,8 h{w} M0,12 h{w} M0,16 h{w}", 135 | w = width 136 | ); 137 | html! { } 138 | } 139 | 140 | fn note(cursor: f32, staff_pos: &StaffPosition) -> Html { 141 | let y = staff_pos.to_y(); 142 | html! { 143 | { NOTEHEAD_WHOLE } 144 | } 145 | } 146 | 147 | fn align_accidentals(accs: &[(Accidental, StaffPosition)]) -> Vec { 148 | if accs.is_empty() { 149 | return Vec::new(); 150 | } 151 | let mut indents = Vec::new(); 152 | let mut top: &StaffPosition = &accs[0].1; 153 | let mut indent = 0.; 154 | for (_, pos) in accs.iter() { 155 | // Accidentals at least a seventh apart can share column 156 | if top.0 - pos.0 >= 6 { 157 | top = &pos; 158 | indent = 0.; 159 | } 160 | indents.push(indent); 161 | indent -= STAFF_SPACE; 162 | } 163 | indents 164 | } 165 | 166 | /// A position in a staff relative to the bottom staff line 167 | /// 168 | /// increasing toward higher pitches 169 | #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] 170 | pub struct StaffPosition(i32); 171 | 172 | impl StaffPosition { 173 | pub fn new(pos: i32) -> Self { 174 | Self(pos) 175 | } 176 | 177 | #[allow(clippy::cast_precision_loss)] 178 | pub fn to_y(&self) -> f32 { 179 | (4. - self.0 as f32 / 2.) * STAFF_SPACE 180 | } 181 | } 182 | 183 | impl ::std::ops::Add for &StaffPosition { 184 | type Output = StaffPosition; 185 | 186 | fn add(self, rhs: i32) -> StaffPosition { 187 | StaffPosition(self.0 + rhs) 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /src/settings.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | pub struct Settings { 4 | link: ComponentLink, 5 | props: Props, 6 | } 7 | 8 | #[derive(Clone, Debug, PartialEq, Properties)] 9 | pub struct Props { 10 | pub allow_dbl_accidentals: bool, 11 | pub on_toggle: Callback, 12 | } 13 | 14 | pub enum Msg { 15 | Toggled, 16 | } 17 | 18 | impl Component for Settings { 19 | type Message = Msg; 20 | type Properties = Props; 21 | 22 | fn create(props: Self::Properties, link: ComponentLink) -> Self { 23 | Self { link, props } 24 | } 25 | 26 | fn update(&mut self, msg: Self::Message) -> ShouldRender { 27 | match msg { 28 | Msg::Toggled => self.props.on_toggle.emit(!self.props.allow_dbl_accidentals) 29 | } 30 | false 31 | } 32 | 33 | fn change(&mut self, props: Self::Properties) -> ShouldRender { 34 | self.props = props; 35 | true 36 | } 37 | 38 | fn view(&self) -> Html { 39 | let on_toggle = self.link.callback(|_| Msg::Toggled); 40 | html! { 41 | <> 42 |

{ "Settings" }

43 |

{ "The settings apply with the next random chord." }

44 |
45 | 52 | 55 |
56 | 57 | 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/tpc_octave.rs: -------------------------------------------------------------------------------- 1 | use tonality::{Interval, Tpc}; 2 | 3 | #[derive(Clone, Debug, PartialEq)] 4 | pub struct TpcOctave(pub Tpc, pub i8); 5 | 6 | impl std::ops::Add for TpcOctave { 7 | type Output = Option; 8 | 9 | fn add(self, rhs: Interval) -> Self::Output { 10 | let tmp = self.0 + rhs; 11 | tmp.map(|tmp| { 12 | if (tmp.step() as i8) < (self.0.step() as i8) { 13 | Self(tmp, self.1 + 1) 14 | } else { 15 | Self(tmp, self.1) 16 | } 17 | }) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /static/.gitignore: -------------------------------------------------------------------------------- 1 | bravura_metadata.json 2 | Bravura.otf 3 | -------------------------------------------------------------------------------- /static/Bravura.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stigjb/chord-quiz/bec94e440d23273978e49a9a8ded2e1d7528046d/static/Bravura.otf -------------------------------------------------------------------------------- /static/Bravura.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stigjb/chord-quiz/bec94e440d23273978e49a9a8ded2e1d7528046d/static/Bravura.woff -------------------------------------------------------------------------------- /static/Bravura.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stigjb/chord-quiz/bec94e440d23273978e49a9a8ded2e1d7528046d/static/Bravura.woff2 -------------------------------------------------------------------------------- /static/bravura.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: "Bravura"; 3 | src: url("Bravura.woff2") format("woff2"), url("Bravura.woff") format("woff"); 4 | } 5 | -------------------------------------------------------------------------------- /static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Stigjb/chord-quiz/bec94e440d23273978e49a9a8ded2e1d7528046d/static/favicon.png -------------------------------------------------------------------------------- /static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Chord Quiz 8 | 9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /static/style.scss: -------------------------------------------------------------------------------- 1 | .bravura { 2 | font-family: Bravura; 3 | } 4 | 5 | .score-wrapper { 6 | max-width: 300px; 7 | } 8 | 9 | .score { 10 | font-size: 16px; 11 | } 12 | 13 | // From https://getbootstrap.com/docs/4.1/examples/sticky-footer/ 14 | .footer { 15 | position: absolute; 16 | bottom: 0; 17 | width: 100%; 18 | height: 60px; 19 | } 20 | 21 | .answer { 22 | height: 3rem; 23 | font-size: larger; 24 | } 25 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); 3 | const CopyWebpackPlugin = require("copy-webpack-plugin"); 4 | 5 | const distPath = path.resolve(__dirname, "dist"); 6 | module.exports = (env, argv) => { 7 | return { 8 | devServer: { 9 | contentBase: distPath, 10 | compress: argv.mode === "production", 11 | port: 8000, 12 | }, 13 | entry: "./bootstrap.js", 14 | output: { 15 | path: distPath, 16 | filename: "chord_quiz.js", 17 | webassemblyModuleFilename: "chord_quiz.wasm", 18 | }, 19 | module: { 20 | rules: [ 21 | { 22 | test: /\.s[ac]ss$/i, 23 | use: ["style-loader", "css-loader", "sass-loader"], 24 | }, 25 | ], 26 | }, 27 | plugins: [ 28 | new CopyWebpackPlugin({ 29 | patterns: [ 30 | { 31 | from: "./static", 32 | to: distPath, 33 | globOptions: { ignore: ["bravura_metadata.json", "Bravura.otf"] } 34 | } 35 | ], 36 | }), 37 | new WasmPackPlugin({ 38 | crateDirectory: ".", 39 | extraArgs: "--no-typescript", 40 | }), 41 | ], 42 | watch: argv.mode !== "production", 43 | }; 44 | }; 45 | --------------------------------------------------------------------------------