Sonic-pi: proposed ring chain: .invert(n)

Created on 12 Jun 2019  路  5Comments  路  Source: sonic-pi-net/sonic-pi

Hi!

There have been a handful of times in which I desired a ring chain that inverts the ring over a specified pitch axis. This would mainly work for rings that are intended as collections of pitches. Would there be interest in adding a feature like this? I have a prototype below, that I'm positive could be more thoughtfully implemented, but for what I typically need, it works well:

class SonicPi::Core::RingVector

  def invert(n)
    self.map {|e| n-e + self.min}
  end

end

puts (scale :c, :major).invert(60)

this will return: (ring 60, 58, 56, 55, 53, 51, 49, 48)

At any rate, thanks so much for this fantastic environment. Much <3

Feedback wanted language

Most helpful comment

Looks good to me - in music theory "inversion" has a specific meaning when applied to counterpoint/melodies (sadly the same word is used for something different when talking about chords).

For reference:

I like the name .invert but it is confusing if people use rings for chords etc. Maybe .invert_around(pitch) instead?

For the implementation @emlyn's implementation looks good. We just need some good tests to make sure it all makes sense.

All 5 comments

This looks quite cool. I think there's a small bug in it though: should it be self.map {|e| 2*n-e}? Otherwise, as it is, you get things like:
(ring 60, 61, 62, 60).invert(60) -> (ring 60, 59, 58, 60), but
(ring 60, 61, 62, 58).invert(60) -> (ring 58, 57, 56, 60).

Also, I wonder if a different name might work better (maybe reflect?) as this one might get confused with chord inversions.

Yeah, conceptually, your solution self.map {|e| 2*n-e} makes more sense according to the way I described it. I like it, thanks :)
Regarding the name, ".reflect" is already in use (similar to .mirror), whereas invert is a term that describes this kind transformation in serialism. I agree that people might confuse it with chord invert though. hm.

Oh yes, I remembered .mirror, but forgot there's also .reflect. In that case maybe .invert is best (at least I can't think of anything better).

@xavriley any thoughts on this? :-)

Looks good to me - in music theory "inversion" has a specific meaning when applied to counterpoint/melodies (sadly the same word is used for something different when talking about chords).

For reference:

I like the name .invert but it is confusing if people use rings for chords etc. Maybe .invert_around(pitch) instead?

For the implementation @emlyn's implementation looks good. We just need some good tests to make sure it all makes sense.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chunseoklee picture chunseoklee  路  4Comments

NathanMEvans picture NathanMEvans  路  5Comments

kivancguckiran picture kivancguckiran  路  4Comments

ostephagus picture ostephagus  路  4Comments

farukbigez picture farukbigez  路  7Comments