Daniel@0
|
1 /* Part of DML (Digital Music Laboratory)
|
Daniel@0
|
2 Copyright 2014-2015 Samer Abdallah, University of London
|
Daniel@0
|
3
|
Daniel@0
|
4 This program is free software; you can redistribute it and/or
|
Daniel@0
|
5 modify it under the terms of the GNU General Public License
|
Daniel@0
|
6 as published by the Free Software Foundation; either version 2
|
Daniel@0
|
7 of the License, or (at your option) any later version.
|
Daniel@0
|
8
|
Daniel@0
|
9 This program is distributed in the hope that it will be useful,
|
Daniel@0
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Daniel@0
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Daniel@0
|
12 GNU General Public License for more details.
|
Daniel@0
|
13
|
Daniel@0
|
14 You should have received a copy of the GNU General Public
|
Daniel@0
|
15 License along with this library; if not, write to the Free Software
|
Daniel@0
|
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Daniel@0
|
17 */
|
Daniel@0
|
18
|
Daniel@0
|
19 :- module(musiclab,
|
Daniel@0
|
20 [ kern_pc_hist/2
|
Daniel@0
|
21 , pitch_class/2
|
Daniel@0
|
22 , pitch_class_number/2
|
Daniel@0
|
23 , pc_number_name/2
|
Daniel@0
|
24 ]).
|
Daniel@0
|
25
|
Daniel@0
|
26 :- use_module(library(persistency)).
|
Daniel@0
|
27
|
Daniel@0
|
28 :- use_module(library(humdrum)).
|
Daniel@0
|
29 :- use_module(library(humdrum/kern)).
|
Daniel@0
|
30 :- use_module(library(humdrum/kernutils)).
|
Daniel@0
|
31 :- use_module(library(humdrum/dynam)).
|
Daniel@0
|
32 :- use_module(library(humdrum/humdrum_world)).
|
Daniel@0
|
33 :- use_module(library(typedef)).
|
Daniel@0
|
34 :- use_module(library(memo)).
|
Daniel@0
|
35
|
Daniel@0
|
36 :- type pitch_class ---> a ; b ; c ; d ; e ; f ; g ; sharp(pitch_class) ; flat(pitch_class).
|
Daniel@0
|
37
|
Daniel@0
|
38 :- volatile_memo kern_pc_hist(+path:ground, -hist:list(pair(pitch_class,nonneg))).
|
Daniel@0
|
39
|
Daniel@0
|
40 % ------------ reading kern ----------------
|
Daniel@0
|
41
|
Daniel@0
|
42 pitch_class_number(sharp(PC),N) :- !, pitch_class_number(PC,M), N is (M+1) mod 12.
|
Daniel@0
|
43 pitch_class_number(flat(PC),N) :- !, pitch_class_number(PC,M), N is (M-1) mod 12.
|
Daniel@0
|
44 pitch_class_number(c,0).
|
Daniel@0
|
45 pitch_class_number(d,2).
|
Daniel@0
|
46 pitch_class_number(e,4).
|
Daniel@0
|
47 pitch_class_number(f,5).
|
Daniel@0
|
48 pitch_class_number(g,7).
|
Daniel@0
|
49 pitch_class_number(a,9).
|
Daniel@0
|
50 pitch_class_number(b,11).
|
Daniel@0
|
51
|
Daniel@0
|
52 kern_pc_hist(Path,Hist) :-
|
Daniel@0
|
53 with_kern_module(Path,utf8,M,findall(PC-N,aggregate(count,mod_note_pc(M,PC),N),Hist)).
|
Daniel@0
|
54
|
Daniel@0
|
55 % pc_hist_to_num(Hist1,Hist2) :-
|
Daniel@0
|
56 % findall(PCN-X, (member(PC-X,Hist1), pitch_class_number(PC,PCN)), Hist2),
|
Daniel@0
|
57 % numlist(0,11,PCNs),
|
Daniel@0
|
58 % maplist(pc_number_name,PCNs,PCNames),
|
Daniel@0
|
59 % maplist(\PCN^Count^(member(PCN-Count,Hist2) -> true; Count=0),PCNs,Counts),
|
Daniel@0
|
60
|
Daniel@0
|
61
|
Daniel@0
|
62 mod_note_pc(M,PC) :-
|
Daniel@0
|
63 M:note(pitch(P),_,_,_),
|
Daniel@0
|
64 pitch_class(P,PC).
|
Daniel@0
|
65
|
Daniel@0
|
66 pc_number_name(0,"c").
|
Daniel@0
|
67 pc_number_name(1,"c#").
|
Daniel@0
|
68 pc_number_name(2,"d").
|
Daniel@0
|
69 pc_number_name(3,"d#").
|
Daniel@0
|
70 pc_number_name(4,"e").
|
Daniel@0
|
71 pc_number_name(5,"f").
|
Daniel@0
|
72 pc_number_name(6,"f#").
|
Daniel@0
|
73 pc_number_name(7,"g").
|
Daniel@0
|
74 pc_number_name(8,"g#").
|
Daniel@0
|
75 pc_number_name(9,"a").
|
Daniel@0
|
76 pc_number_name(10,"a#").
|
Daniel@0
|
77 pc_number_name(11,"b").
|
Daniel@0
|
78
|
Daniel@0
|
79
|
Daniel@0
|
80
|