Skip to content

music21: figure out how the heck to use getContextByClass() #10

@melodysium

Description

@melodysium

commit: 9825ee1

brain dump:

the situation.

given:

  • a Music21Object el
  • a Stream root that possibly contains it at some level
  • a Music21StreamType cls for some Stream type container

I want to know the closest container to el within root's hierarchy of type cls

the problem.

i thought i could use getContextByClass() for this - it seems perfect!
but that method instead seems to be doing much more complicated things like seeking backwards in any containers that directly hold el, or even containers that indirectly hold el.

the actual solution for my needs.

i'm gonna build my own logic on top of containerInHierarchy(), which retrieves the immediate container of el in root.
i can repeat that to build a parent tree from el to root, and then get the first container of type cls.

the wtf that has me still confused.

  • given the above commit,
  • when i make a stream of only some parts in a multi-part score (and save it to a local variable harmonic_parts,
  • and then make another stream of all measures in the parts from the prior stream (and save it to a local variable scoped_measures,
  • and then loop through each measure m in scoped_measures and query each one's m.getContextByClass(Part),
  • why does that return Part2 even for measures in Part1?

answer: because harmonic_parts is coming back somewhere in m.contextSites()

  • why the heck?
  • i think this has something to do with activeSite? like if m.activeSite is Part1 it'll come back fine, but if m.activeSite is harmonic_parts (how the heck did that happen?? m is not even in harmonic parts????) then it'll return harmonic_parts where it's not supposed to
  • is this a music21 bug? is this weird behavior like described in https://www.music21.org/music21docs/usersGuide/usersGuide_58_sitesContext.html?

todo for future

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: music21relevant to parsing of music transcription input filesstatus: laterThis issue or pull request already existstype: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions