Daniel@0: /* Part of DML (Digital Music Laboratory) Daniel@0: Copyright 2014-2015 Samer Abdallah, University of London Daniel@0: Daniel@0: This program is free software; you can redistribute it and/or Daniel@0: modify it under the terms of the GNU General Public License Daniel@0: as published by the Free Software Foundation; either version 2 Daniel@0: of the License, or (at your option) any later version. Daniel@0: Daniel@0: This program is distributed in the hope that it will be useful, Daniel@0: but WITHOUT ANY WARRANTY; without even the implied warranty of Daniel@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Daniel@0: GNU General Public License for more details. Daniel@0: Daniel@0: You should have received a copy of the GNU General Public Daniel@0: License along with this library; if not, write to the Free Software Daniel@0: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Daniel@0: */ Daniel@0: Daniel@0: :- module(musiclab, Daniel@0: [ kern_pc_hist/2 Daniel@0: , pitch_class/2 Daniel@0: , pitch_class_number/2 Daniel@0: , pc_number_name/2 Daniel@0: ]). Daniel@0: Daniel@0: :- use_module(library(persistency)). Daniel@0: Daniel@0: :- use_module(library(humdrum)). Daniel@0: :- use_module(library(humdrum/kern)). Daniel@0: :- use_module(library(humdrum/kernutils)). Daniel@0: :- use_module(library(humdrum/dynam)). Daniel@0: :- use_module(library(humdrum/humdrum_world)). Daniel@0: :- use_module(library(typedef)). Daniel@0: :- use_module(library(memo)). Daniel@0: Daniel@0: :- type pitch_class ---> a ; b ; c ; d ; e ; f ; g ; sharp(pitch_class) ; flat(pitch_class). Daniel@0: Daniel@0: :- volatile_memo kern_pc_hist(+path:ground, -hist:list(pair(pitch_class,nonneg))). Daniel@0: Daniel@0: % ------------ reading kern ---------------- Daniel@0: Daniel@0: pitch_class_number(sharp(PC),N) :- !, pitch_class_number(PC,M), N is (M+1) mod 12. Daniel@0: pitch_class_number(flat(PC),N) :- !, pitch_class_number(PC,M), N is (M-1) mod 12. Daniel@0: pitch_class_number(c,0). Daniel@0: pitch_class_number(d,2). Daniel@0: pitch_class_number(e,4). Daniel@0: pitch_class_number(f,5). Daniel@0: pitch_class_number(g,7). Daniel@0: pitch_class_number(a,9). Daniel@0: pitch_class_number(b,11). Daniel@0: Daniel@0: kern_pc_hist(Path,Hist) :- Daniel@0: with_kern_module(Path,utf8,M,findall(PC-N,aggregate(count,mod_note_pc(M,PC),N),Hist)). Daniel@0: Daniel@0: % pc_hist_to_num(Hist1,Hist2) :- Daniel@0: % findall(PCN-X, (member(PC-X,Hist1), pitch_class_number(PC,PCN)), Hist2), Daniel@0: % numlist(0,11,PCNs), Daniel@0: % maplist(pc_number_name,PCNs,PCNames), Daniel@0: % maplist(\PCN^Count^(member(PCN-Count,Hist2) -> true; Count=0),PCNs,Counts), Daniel@0: Daniel@0: Daniel@0: mod_note_pc(M,PC) :- Daniel@0: M:note(pitch(P),_,_,_), Daniel@0: pitch_class(P,PC). Daniel@0: Daniel@0: pc_number_name(0,"c"). Daniel@0: pc_number_name(1,"c#"). Daniel@0: pc_number_name(2,"d"). Daniel@0: pc_number_name(3,"d#"). Daniel@0: pc_number_name(4,"e"). Daniel@0: pc_number_name(5,"f"). Daniel@0: pc_number_name(6,"f#"). Daniel@0: pc_number_name(7,"g"). Daniel@0: pc_number_name(8,"g#"). Daniel@0: pc_number_name(9,"a"). Daniel@0: pc_number_name(10,"a#"). Daniel@0: pc_number_name(11,"b"). Daniel@0: Daniel@0: Daniel@0: