Re: [racket-users] table lookup shorthands?

2017-08-16 Thread Luis Sanjuán
On Wednesday, August 16, 2017 at 3:42:38 PM UTC+2, Alex Knauth wrote:
> > On Aug 8, 2017, at 10:42 AM, Luis Sanjuán  wrote:
> > 
> > On Tuesday, August 8, 2017 at 3:16:46 PM UTC+2, Alex Knauth wrote:
> 
> >> I've been basing it on the chord-labeling algorithm in a paper I found, 
> >> "Algorithms for Chordal Analysis" by Bryan Pardo and William P. 
> >> Birmingham, but there are a few situations where this doesn't label the 
> >> correct chord. In particular when there are something like short arpeggios 
> >> in the harmony and longer passing tones or suspensions in the melody, it 
> >> gives more weight to the passing tones and suspensions.
> 
> > Looks interesting! Mine, written in a couple of days, is much simpler. It 
> > just arranges chords to match chord patterns (what Pardo an Birmingham call 
> > templates, as I read) and labels them accordingly. First, it assumes chord 
> > boundaries are given, say, for instance, each arpeggio of Bach's Prelude I 
> > in das Wohltemperierte Klavier, and there is no attempt to score 
> > alternatives.
> > 
> > The task in a real world scenario looks really demanding. Although I've 
> > never thought of it, for what I've skim-read I agree with P and B that, 
> > first, we need ways to determine chord boundaries, and secondly, algorithms 
> > to score possible interpretations. And, at first glance, it seems to me 
> > that both tasks cannot be completely isolated, since boundaries may depend 
> > on the interpretation.
> 
> That's true. Maybe I need to implement both sides of the algorithm before I 
> look at passing tones. Some of the suspensions in particular would make sense 
> as two chords instead of one. For longer passing tones, it might interpret it 
> as one-chord-per-melody-note like in a hymn, but maybe that's useful enough 
> and I can hopefully simplify the output by hand later.
> 
> > On the other hand, even chord patterns (which of them are suitable and the 
> > probability of its occurrence) may differ according to the historic and 
> > stylistic context, even by composer, as it is actually the case in real 
> > music.

Looks promising.

By the way, motivated by the discussion I have searched for similar efforts. 
You may be aware of this one:

https://halshs.archives-ouvertes.fr/hal-01161435/document [description]

http://grfia.dlsi.ua.es/cm/projects/drims/software.php [code]

It is also based on P, and written in Common Lisp.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] table lookup shorthands?

2017-08-16 Thread Alex Knauth

> On Aug 8, 2017, at 10:42 AM, Luis Sanjuán  wrote:
> 
> On Tuesday, August 8, 2017 at 3:16:46 PM UTC+2, Alex Knauth wrote:

>> I've been basing it on the chord-labeling algorithm in a paper I found, 
>> "Algorithms for Chordal Analysis" by Bryan Pardo and William P. Birmingham, 
>> but there are a few situations where this doesn't label the correct chord. 
>> In particular when there are something like short arpeggios in the harmony 
>> and longer passing tones or suspensions in the melody, it gives more weight 
>> to the passing tones and suspensions.

> Looks interesting! Mine, written in a couple of days, is much simpler. It 
> just arranges chords to match chord patterns (what Pardo an Birmingham call 
> templates, as I read) and labels them accordingly. First, it assumes chord 
> boundaries are given, say, for instance, each arpeggio of Bach's Prelude I in 
> das Wohltemperierte Klavier, and there is no attempt to score alternatives.
> 
> The task in a real world scenario looks really demanding. Although I've never 
> thought of it, for what I've skim-read I agree with P and B that, first, we 
> need ways to determine chord boundaries, and secondly, algorithms to score 
> possible interpretations. And, at first glance, it seems to me that both 
> tasks cannot be completely isolated, since boundaries may depend on the 
> interpretation.

That's true. Maybe I need to implement both sides of the algorithm before I 
look at passing tones. Some of the suspensions in particular would make sense 
as two chords instead of one. For longer passing tones, it might interpret it 
as one-chord-per-melody-note like in a hymn, but maybe that's useful enough and 
I can hopefully simplify the output by hand later.

> On the other hand, even chord patterns (which of them are suitable and the 
> probability of its occurrence) may differ according to the historic and 
> stylistic context, even by composer, as it is actually the case in real music.


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] table lookup shorthands?

2017-08-08 Thread Luis Sanjuán
On Tuesday, August 8, 2017 at 3:16:46 PM UTC+2, Alex Knauth wrote:
> > On Aug 8, 2017, at 8:15 AM, Luis Sanjuán  wrote:
> > 
> > Hi, phillip
> > 
> > As far as I'm concerned, professional musician too, I wrote a little app, 
> > just a prototype, using a similar representation of pitch classes and 
> > intervals for basic chord analysis. Since actual chords can be seen as 
> > sequences of intervals, its analysis can be reduced to determine the chord 
> > patterns actual chords match. This leads to at least all possible 
> > interpretations. Further work, some AI for sure, would be needed to select 
> > proper interpretations. Without that, though, a summary of possible matches 
> > cuold be as is useful for students in the first years of Harmony
> 
> I've been trying to do something similar, representing chord-kinds as 
> sequences of intervals and matching the possible chord patterns to the notes.
> 
> I've been basing it on the chord-labeling algorithm in a paper I found, 
> "Algorithms for Chordal Analysis" by Bryan Pardo and William P. Birmingham, 
> but there are a few situations where this doesn't label the correct chord. In 
> particular when there are something like short arpeggios in the harmony and 
> longer passing tones or suspensions in the melody, it gives more weight to 
> the passing tones and suspensions.
> 
> Is that similar to the strategy you used? Is there any way to deal with 
> passing tones like this?
> 
> Alex Knauth

Hi Alex.

BTW, I have just skim over your music-theory code in github. You have already 
done a really great work there! Hope having the time to look into it deeper. 
Thanks for sharing.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] table lookup shorthands?

2017-08-08 Thread Luis Sanjuán
On Tuesday, August 8, 2017 at 3:16:46 PM UTC+2, Alex Knauth wrote:
> > On Aug 8, 2017, at 8:15 AM, Luis Sanjuán  wrote:
> > 
> > Hi, phillip
> > 
> > As far as I'm concerned, professional musician too, I wrote a little app, 
> > just a prototype, using a similar representation of pitch classes and 
> > intervals for basic chord analysis. Since actual chords can be seen as 
> > sequences of intervals, its analysis can be reduced to determine the chord 
> > patterns actual chords match. This leads to at least all possible 
> > interpretations. Further work, some AI for sure, would be needed to select 
> > proper interpretations. Without that, though, a summary of possible matches 
> > cuold be as is useful for students in the first years of Harmony
> 
> I've been trying to do something similar, representing chord-kinds as 
> sequences of intervals and matching the possible chord patterns to the notes.
> 
> I've been basing it on the chord-labeling algorithm in a paper I found, 
> "Algorithms for Chordal Analysis" by Bryan Pardo and William P. Birmingham, 
> but there are a few situations where this doesn't label the correct chord. In 
> particular when there are something like short arpeggios in the harmony and 
> longer passing tones or suspensions in the melody, it gives more weight to 
> the passing tones and suspensions.
> 
> Is that similar to the strategy you used? Is there any way to deal with 
> passing tones like this?
> 
> Alex Knauth

Regarding passing notes and suspensions, it occurs to me that one could try to 
mimic the way musicians cope with them. If your chord patterns don't include 
too many varieties, one would get more than a few 'unknown' chords. Still one 
could later decide from the context, so if, for instance, most of the chord 
progression in which the unknown chord is inserted can be labeled, one could 
discard or label those added notes in the unknown chord as 'ornaments' and 
label the chord accordingly.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] table lookup shorthands?

2017-08-08 Thread Luis Sanjuán
On Tuesday, August 8, 2017 at 3:16:46 PM UTC+2, Alex Knauth wrote:
> > On Aug 8, 2017, at 8:15 AM, Luis Sanjuán  wrote:
> > 
> > Hi, phillip
> > 
> > As far as I'm concerned, professional musician too, I wrote a little app, 
> > just a prototype, using a similar representation of pitch classes and 
> > intervals for basic chord analysis. Since actual chords can be seen as 
> > sequences of intervals, its analysis can be reduced to determine the chord 
> > patterns actual chords match. This leads to at least all possible 
> > interpretations. Further work, some AI for sure, would be needed to select 
> > proper interpretations. Without that, though, a summary of possible matches 
> > cuold be as is useful for students in the first years of Harmony
> 
> I've been trying to do something similar, representing chord-kinds as 
> sequences of intervals and matching the possible chord patterns to the notes.
> 
> I've been basing it on the chord-labeling algorithm in a paper I found, 
> "Algorithms for Chordal Analysis" by Bryan Pardo and William P. Birmingham, 
> but there are a few situations where this doesn't label the correct chord. In 
> particular when there are something like short arpeggios in the harmony and 
> longer passing tones or suspensions in the melody, it gives more weight to 
> the passing tones and suspensions.
> 
> Is that similar to the strategy you used? Is there any way to deal with 
> passing tones like this?
> 
> Alex Knauth

Looks interesting! Mine, written in a couple of days, is much simpler. It just 
arranges chords to match chord patterns (what Pardo an Birmingham call 
templates, as I read) and labels them accordingly. First, it assumes chord 
boundaries are given, say, for instance, each arpeggio of Bach's Prelude I in 
das Wohltemperierte Klavier, and there is no attempt to score alternatives.

The task in a real world scenario looks really demanding. Although I've never 
thought of it, for what I've skim-read I agree with P and B that, first, we 
need ways to determine chord boundaries, and secondly, algorithms to score 
possible interpretations. And, at first glance, it seems to me that both tasks 
cannot be completely isolated, since boundaries may depend on the 
interpretation. On the other hand, even chord patterns (which of them are 
suitable and the probability of its occurrence) may differ according to the 
historic and stylistic context, even by composer, as it is actually the case in 
real music.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] table lookup shorthands?

2017-08-08 Thread Alex Knauth

> On Aug 8, 2017, at 8:15 AM, Luis Sanjuán  wrote:
> 
> Hi, phillip
> 
> As far as I'm concerned, professional musician too, I wrote a little app, 
> just a prototype, using a similar representation of pitch classes and 
> intervals for basic chord analysis. Since actual chords can be seen as 
> sequences of intervals, its analysis can be reduced to determine the chord 
> patterns actual chords match. This leads to at least all possible 
> interpretations. Further work, some AI for sure, would be needed to select 
> proper interpretations. Without that, though, a summary of possible matches 
> cuold be as is useful for students in the first years of Harmony

I've been trying to do something similar, representing chord-kinds as sequences 
of intervals and matching the possible chord patterns to the notes.

I've been basing it on the chord-labeling algorithm in a paper I found, 
"Algorithms for Chordal Analysis" by Bryan Pardo and William P. Birmingham, but 
there are a few situations where this doesn't label the correct chord. In 
particular when there are something like short arpeggios in the harmony and 
longer passing tones or suspensions in the melody, it gives more weight to the 
passing tones and suspensions.

Is that similar to the strategy you used? Is there any way to deal with passing 
tones like this?

Alex Knauth

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] table lookup shorthands?

2017-08-07 Thread Luis Sanjuán
EDIT.

In the description of the 'Interval' data type, replace 'notes'  with 
'pitch-classes'

In the signature of the function `interval`, replace 'Nat' with 'Interval'

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] table lookup shorthands?

2017-08-07 Thread Luis Sanjuán
Expanding on what Alex has already point out, you can do something like this:

;; PitchClass is one of
(define C 0)
(define C# 1)
(define D 2)
(define D# 3)
(define E 4)
(define F 5)
(define F# 6)
(define G 7)
(define G# 8)
(define A 9)
(define A# 10)
(define B 11)

;; Interval is Natural
;; number of semitones between two notes
;; assume: ascending intervals
(define FIFTH 7)  ;number of semitones
(define FOURTH 5) ;ditto

;; Direction is "up" or "down"
;; the direction of rotation around a circle of fifths
;; "up" means clockwise (ascending fifths), "down" counterclockwise
;; (descending fifths)

;; PitchClass PitchClass -> Nat
;; produce number of semitones between pc1 and pc2
;; where pc1 is lower than pc2
(define (interval pc1 pc2)
  (modulo (- pc2 pc1) 12))

;; PitchClass Interval -> PitchClass
;; produce the pitch class at the given ascending interval from pc
(define (next pc interval)
  (modulo (+ pc interval) 12))

;; Some 'next' concrete functions, for convenience
(define perfect-fifth (curryr next FIFTH))
(define perfect-fourth (curryr next FOURTH))

;; PitchClass PitchClass Direction -> PitchClass (listof PitchClass) Nat
;; ...
(define (fifths-from-to from to by)
  (define-values (next count)
(if (string=? by "up")
(values perfect-fifth add1)
(values perfect-fourth sub1)))
  (for/fold ([init from]
 [circle-up-to null]
 [fifths# 0])
([i (in-naturals)]
 #:break (equal? init to))
(values (next init)
(append circle-up-to (list init))
(count fifths#

The last function produces as last value the distance in ascending/descending 
fifths as you has hardcoded in the table. There might be better for forms to 
implement the same or you can use another style. Or you can produce something 
simpler like the positive count of fifths/forths, and convert it with another 
function to obtain the representation (positive/negative numbers) you want. As 
a bonus the function produces the actual ascending/descending fifths between 
the initial one (from) up to the final one (to) fifth, not included, it is the 
second value of the result. Anyway, you could pass the result to another 
function to do whatever you like with those values.

The rationale is just that each pitch-class is represented, as usual in music, 
by the way, by an integer from 0 to 11. This makes easier to work on 
intervallics by simple arithmetic. Based on it producing sequences of 
pitch-classes at the same intervallic like the circle of fifths is just a 
matter of generating it recursively. In addition, as a fourth is just the 
inversion of a fifth, you can traverse/generate the circle of descending fifths 
using fourths. 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] table lookup shorthands?

2017-08-06 Thread Alex Knauth

> On Aug 6, 2017, at 6:16 PM, Jordan Johnson  wrote:
> 
> Hi all,
> 
> I’m writing some music-related code for which I find myself using a lot of 
> lookup tables, following the pattern of making an alist or hash table and 
> then writing a function that consults the table. I wound up writing a macro 
> for this pattern; one example of its use is:
> 
> ;; key->fifths : PitchName -> Int[-7..7]
> ;; tells how many perfect fifths above C the given pitch is (and
> ;; therefore how many sharps or flats its key signature has)
> (define-lookup-function key->fifths
>  [C 0] [G 1] [D 2] [A 3] [E 4] [B 5]
>  [F# 6] [F♯ 6]
>  [C# 7] [C♯ 7]
>  [F -1]
>  [Bb -2] [Eb -3] [Ab -4] [Db -5] [Gb -6] [Cb -7]
>  [B♭ -2] [E♭ -3] [A♭ -4] [D♭ -5] [G♭ -6] [C♭ -7])
> ;; Ex:
> (key->fifths 'Gb) ;; -> -6
> 
> This seems like a simple and common enough pattern that there must be such a 
> facility in some Racket library out there already, but I haven’t found one. 
> Am I reinventing a wheel here?
> 
> Thanks,
> Jordan

What I've done for situations like these is define notes like C and D not as 
symbols, but as data structures that contain the numbers you need. So for 
instance I would define:

(struct pitch-class [chromatic-number])

(define C (pitch-class 0))
(define C#/D♭ (pitch-class 1))
(define D (pitch-class 2))
(define D#/E♭ (pitch-class 3))
(define E (pitch-class 4))
(define F (pitch-class 5))
etc.

When the notes are defined like this, the number of fifths can be a 
mathematical function instead of a lookup, if you can find the function that 
maps chromatic numbers to fifths.
  

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] table lookup shorthands?

2017-08-06 Thread Jordan Johnson
Hi all,

I’m writing some music-related code for which I find myself using a lot of 
lookup tables, following the pattern of making an alist or hash table and then 
writing a function that consults the table. I wound up writing a macro for this 
pattern; one example of its use is:

;; key->fifths : PitchName -> Int[-7..7]
;; tells how many perfect fifths above C the given pitch is (and
;; therefore how many sharps or flats its key signature has)
(define-lookup-function key->fifths
  [C 0] [G 1] [D 2] [A 3] [E 4] [B 5]
  [F# 6] [F♯ 6]
  [C# 7] [C♯ 7]
  [F -1]
  [Bb -2] [Eb -3] [Ab -4] [Db -5] [Gb -6] [Cb -7]
  [B♭ -2] [E♭ -3] [A♭ -4] [D♭ -5] [G♭ -6] [C♭ -7])
;; Ex:
(key->fifths 'Gb) ;; -> -6

This seems like a simple and common enough pattern that there must be such a 
facility in some Racket library out there already, but I haven’t found one. Am 
I reinventing a wheel here?

Thanks,
Jordan

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.