-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic_utils.pl
47 lines (40 loc) · 1.38 KB
/
music_utils.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
:- module(music_utils, [
interlineAtStart/2, interlineAtEnd/2, interlineAtX/3,
interlineAt/3, interlineAt/4,
listSum/2, average/2, ccxOnStaffline/5,
atom_number//2]).
:- use_module(library(clpBNR)).
:- use_module(library(delay)).
:- use_module(seg).
:- use_module(geo).
:- use_module(utils).
:- use_module(cond).
listSum([],0).
listSum([X | Xs],Sum) :-
{Sum == X+S},
listSum(Xs,S).
average(List, Average) :-
listSum(List, Sum),
length(List, Length),
{Average == Sum / Length}.
distance(X, Y, Z) :-
{ Z == abs(Y - X) }.
interlineAtStart(Stafflines, Interline) :-
interlineAt(Stafflines, segStartY, Interline).
interlineAtEnd(Stafflines, Interline) :-
interlineAt(Stafflines, segEndY, Interline).
interlineAtX(Stafflines, X, Interline) :-
debug(music_utils, "interlineAtX Stafflines ~p~n", [Stafflines]),
interlineAt(Stafflines, {X}/[Seg, Y]>>(segYAtX(Seg, Y, X)), Interline).
interlineAt(Stafflines, Getter, Interline) :-
interlineAt(Stafflines, Getter, Interline, _).
interlineAt(Stafflines, Getter, Interline, Interlines) :-
maplist(Getter, Stafflines, Ys),
convlist2(distance, Ys, Interlines),
average(Interlines, Interline).
ccxOnStaffline(Stafflines, Ccx, Etiq, NumStaffline, Eps) :-
ccxEtiqsCond(Ccx, Etiq),
nth1(NumStaffline, Stafflines, Staffline),
ccxOnSegCond(Staffline, Ccx, Eps).
atom_number(Atom, Number) -->
{ delay(atom_number(Atom, Number)) }.