pentatonic scale

22 views
Skip to first unread message

A.G. Hamill

unread,
Mar 17, 2024, 6:00:31 PMMar 17
to music21
Hello group,

A quick question: Is it true that Music21 has no built-in method for constructing a pentatonic scale given a starting pitch (like it does for other scales major, minor, octatonic, etc.)?

I searched the documentation on the word "pentatonic" and only got two results, both were a dead-ends for me.

Thanks much,
Anne

Georges Dimitrov

unread,
Mar 18, 2024, 10:04:09 AMMar 18
to music...@googlegroups.com
Hi,

This is something I noted too, and I created custom classes for it:

import music21
from music21.scale import intervalNetwork

class AbstractPentatonicScale(music21.scale.AbstractScale):
    def __init__(self, mode=None):
        super().__init__()
        self.type = "Abstract Pentatonic"
        # all pentatonic scales are octave duplicating
        self.octaveDuplicating = True
        # here, accept None
        self.buildNetwork(mode=mode)

    def buildNetwork(self, mode=None):
        src_list = ("M2", "M2", "m3", "M2", "m3")
        if mode in (None, 1, "major", "Major"):
            interval_list = src_list
            self.tonicDegree = 1
        elif mode == 2:
            interval_list = src_list[1:] + src_list[:1]
            self.tonicDegree = 1
        elif mode == 3:
            interval_list = src_list[2:] + src_list[:2]
            self.tonicDegree = 1
        elif mode == 4:
            interval_list = src_list[3:] + src_list[:3]
            self.tonicDegree = 1
        elif mode in (5, "minor", "Minor"):
            interval_list = src_list[4:] + src_list[:4]
            self.tonicDegree = 1
        else:
            raise music21.scale.ScaleException(
                f"cannot create a scale of the following mode: {mode}"
            )
        self._net = intervalNetwork.IntervalNetwork(
            interval_list,
            octaveDuplicating=self.octaveDuplicating,
            pitchSimplification="none",
        )
        # might also set weights for tonic and dominant here


class PentatonicScale(music21.scale.ConcreteScale):
    usePitchDegreeCache = True

    def __init__(self, tonic=None, mode=None):
        super().__init__(tonic=tonic)
        self._abstract = AbstractPentatonicScale(mode=mode)
        self.type = "Pentatonic"

I made these for my procedural composition library (https://github.com/georgesdimitrov/arvo) which I started developing in 2021, and unfortunately didn’t have much time to maintain, but I’ve been progressively working on a major update which I should publish this week! The update will add a lot of functionality (such as those extra scales), and compatibility with music21 v9.

Georges Dimitrov




--
--
To Post: email music...@googlegroups.com
To Unsubscribe: email music21list...@googlegroups.com
Archives, Options, etc: http://groups.google.com/group/music21list

---
You received this message because you are subscribed to the Google Groups "music21" group.
To unsubscribe from this group and stop receiving emails from it, send an email to music21list...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/music21list/e9afd62a-773b-47b4-867e-94dcd0a8e373n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages