Skip to content

voice.makeRests() fills in missing notes in tuplets incorrectly #1237

Closed

Description

@gregchapman-dev

music21 version

7.2.1

Problem summary

If I put a single triplet eighth-note rest at the end of a 3-quarter-note voice (leaving a starting gap of 11 triplet eighth notes) and then call makeRests, it inserts a rest with duration.tuplets = (<music21.duration.Tuplet 12/11/16th>,) instead of what I would expect: duration.tuplets = (<music21.duration.Tuplet 3/2/eighth>,). The actual duration.quarterLength is correct (11/3ql), but I don't understand that weird tuplet choice (12 actual 16th notes in the space of 11 normal 16th notes).

Steps to reproduce

from fractions import Fraction
import music21 as m21
restVoice = m21.stream.Voice()
secondNote = m21.note.Rest()
secondNote.duration = m21.duration.Duration(Fraction(1, 3))
restVoice.insert(Fraction(11, 3), secondNote)
restVoice.makeRests(inPlace=True, hideRests=True)
firstNote = restVoice.notesAndRests[0]
print('firstNote = ', firstNote)
print('firstNote tuplets = ', firstNote.duration.tuplets)
print('secondNote = ', secondNote)
print('secondNote tuplets = ', secondNote.duration.tuplets)

Expected vs. actual behavior

More information

Activity

  1. mscuthbert commented on Feb 27, 2022

    @mscuthbert
    Member

    What happens if you give a time signature?

  2. gregchapman-dev commented on Feb 27, 2022

    @gregchapman-dev
    ContributorAuthor
  3. gregchapman-dev commented on Feb 27, 2022

    @gregchapman-dev
    ContributorAuthor
  4. gregchapman-dev commented on Feb 27, 2022

    @gregchapman-dev
    ContributorAuthor
  5. jacobtylerwalls commented on Feb 27, 2022

    @jacobtylerwalls
    Member

    Most likely another manifestation of #904.

    When you say this works with a time signature (albeit not in a real world scenario), what is the result? A half rest, quarter rest, and two triplet eighths? If so, I would have thought #992 was needed for that (speaking of which, the procedure described there is probably your best workaround for now).

  6. gregchapman-dev commented on Feb 27, 2022

    @gregchapman-dev
    ContributorAuthor
  7. jacobtylerwalls commented on Feb 27, 2022

    @jacobtylerwalls
    Member

    Another very similar discussion at #572.

  8. gregchapman-dev commented on Feb 27, 2022

    @gregchapman-dev
    ContributorAuthor
  9. gregchapman-dev commented on Feb 27, 2022

    @gregchapman-dev
    ContributorAuthor
  10. gregchapman-dev commented on Feb 27, 2022

    @gregchapman-dev
    ContributorAuthor

    Here's my code for that use of TupletFixer:

    from fractions import Fraction
    import music21 as m21
    print(m21.__version__)
    
    restVoice = m21.stream.Voice()
    timesig = m21.meter.TimeSignature('4/4')
    #restVoice.insert(0, timesig)
    secondNote = m21.note.Rest()
    secondNote.duration = m21.duration.Duration(Fraction(1, 3))
    restVoice.insert(Fraction(11, 3), secondNote)
    restVoice.makeRests(inPlace=True,
                        hideRests=True) #,
                        #fillGaps=True,
                        #timeRangeFromBarDuration=True,
                        #refStreamOrTimeRange=timesig)
    tf = m21.duration.TupletFixer(restVoice)
    tupletGroups = tf.findTupletGroups()
    for tg in tupletGroups:
        tf.fixBrokenTupletDuration(tg)
    
    firstNote = restVoice.notesAndRests[0]
    print('firstNote = ', firstNote)
    print('firstNote tuplets = ', firstNote.duration.tuplets)
    print('secondNote = ', secondNote)
    print('secondNote tuplets = ', secondNote.duration.tuplets)
    
  11. jacobtylerwalls commented on Mar 1, 2022

    @jacobtylerwalls
    Member

    Thanks for looking into some workarounds.

    I'll be closing as a duplicate of #572, but I went ahead and re-opened a PR to fix it (#1240), so I'm hoping you might test it out. It's not truly mergeable until we have a solution for #904, but I'll open something for that soon and figured this way testing/feedback could get going, if you have some. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions