music21/corpus/
virtual_corpus.rs1use crate::common::formats::find_format_ext_url;
5
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub struct VirtualWork {
9 pub class: &'static str,
11 pub composer: &'static str,
13 pub title: &'static str,
15 pub corpus_path: &'static str,
17 pub urls: &'static [&'static str],
19}
20
21pub const VIRTUAL_WORKS: [VirtualWork; 9] = [
23 VirtualWork {
24 class: "BachBWV1007Prelude",
25 composer: "Johann Sebastian Bach",
26 title: "Prelude from Cello Suite No. 1 in G Major, BWV 1007",
27 corpus_path: "bach/bwv1007/prelude",
28 urls: &[
29 "https://kern.ccarh.org/cgi-bin/ksdata?l=cc/bach/cello&file=bwv1007-01.krn&f=xml",
30 "https://kern.ccarh.org/cgi-bin/ksdata?l=cc/bach/cello&file=bwv1007-01.krn&f=kern",
31 ],
32 },
33 VirtualWork {
34 class: "BachBWV772",
35 composer: "Johann Sebastian Bach",
36 title: "Invention No. 1 in C Major, BWV 772",
37 corpus_path: "bach/bwv772",
38 urls: &[
39 "https://kern.ccarh.org/cgi-bin/ksdata?l=osu/classical/bach/inventions&file=inven01.krn&f=xml",
40 ],
41 },
42 VirtualWork {
43 class: "BachBWV773",
44 composer: "Johann Sebastian Bach",
45 title: "Invention No. 2 in C Minor, BWV 773",
46 corpus_path: "bach/bwv773",
47 urls: &[
48 "https://kern.ccarh.org/cgi-bin/ksdata?l=osu/classical/bach/inventions&file=inven02.krn&f=xml",
49 "https://kern.ccarh.org/cgi-bin/ksdata?l=osu/classical/bach/inventions&file=inven02.krn&f=kern",
50 ],
51 },
52 VirtualWork {
53 class: "ColtraneGiantSteps",
54 composer: "John Coltrane",
55 title: "Giant Steps",
56 corpus_path: "coltrane/giantSteps",
57 urls: &[
58 "http://impromastering.com/uploads/transcription_file/file/196/Giant_Steps__John_Coltrane_C.xml",
59 ],
60 },
61 VirtualWork {
62 class: "SchubertD576",
63 composer: "Franz Schubert",
64 title: "13 Variations on a Theme by Anselm Hüttenbrenner",
65 corpus_path: "schubert/d576-1",
66 urls: &[
67 "https://kern.ccarh.org/cgi-bin/ksdata?l=cc/schubert/piano/d0576&file=d0576-06.krn&f=xml",
68 ],
69 },
70 VirtualWork {
71 class: "SchubertD5762",
72 composer: "Franz Schubert",
73 title: "13 Variations on a Theme by Anselm Hüttenbrenner",
74 corpus_path: "schubert/d576-2",
75 urls: &[
76 "https://kern.ccarh.org/cgi-bin/ksdata?l=users/craig/classical/schubert/piano/d0576&file=d0576-02.krn&f=xml",
77 ],
78 },
79 VirtualWork {
80 class: "SchubertD5763",
81 composer: "Franz Schubert",
82 title: "13 Variations on a Theme by Anselm Hüttenbrenner",
83 corpus_path: "schubert/d576-3",
84 urls: &[
85 "https://kern.ccarh.org/cgi-bin/ksdata?l=users/craig/classical/schubert/piano/d0576&file=d0576-03.krn&f=xml",
86 ],
87 },
88 VirtualWork {
89 class: "SchubertD5764",
90 composer: "Franz Schubert",
91 title: "13 Variations on a Theme by Anselm Hüttenbrenner",
92 corpus_path: "schubert/d576-4",
93 urls: &[
94 "https://kern.ccarh.org/cgi-bin/ksdata?l=users/craig/classical/schubert/piano/d0576&file=d0576-04.krn&f=xml",
95 ],
96 },
97 VirtualWork {
98 class: "PachelbelCanonD",
99 composer: "Johann Pachelbel",
100 title: "Canon in D Major",
101 corpus_path: "pachelbel/canon",
102 urls: &["https://kern.ccarh.org/cgi-bin/ksdata?l=cc/pachelbel&file=canon.krn&f=xml"],
103 },
104];
105
106pub fn urls_by_ext<'a>(urls: &[&'a str], extensions: &[&str]) -> Vec<&'a str> {
109 let mut found = Vec::new();
110 for extension in extensions {
111 for url in urls {
112 let (_, found_extension) = find_format_ext_url(url);
113 if found_extension.as_deref() == Some(*extension) {
114 found.push(*url);
115 }
116 }
117 }
118 found
119}
120
121#[cfg(test)]
122mod tests {
123 use super::*;
124
125 #[test]
126 fn an_address_is_found_by_its_format() {
127 let prelude = VIRTUAL_WORKS[0];
128 assert_eq!(urls_by_ext(prelude.urls, &[".xml"]), [prelude.urls[0]]);
129 assert_eq!(urls_by_ext(prelude.urls, &[".krn"]), [prelude.urls[1]]);
130 assert!(urls_by_ext(prelude.urls, &[".mid"]).is_empty());
131 }
132}