Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generatePatternSeqs features #21

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

colinsullivan
Copy link

Hello,

This introduces 2 features to the generatePatternSeqs method, as well as unit tests & MIDI files demonstrating the features.

  • Adds an option to parse velocity, and return a 3-tuple instead of a 2-tuple, with the third element a velocity (from 0.0 - 1.0).
  • Adds two options to add rests at the beginning and end of the pattern, useful for exporting MIDI files intended to be used as loops. This is explained further below.

Consider this MIDI file:

image

This would create a pattern like:

[
  [48, 1],
  [\rest, 1],
  [48, 1]
]

Now consider this MIDI file:

image

Without this PR, generatePatternSeqs will generate the same pattern. But I want to put a rest in there, useful when loading loops in the MIDI sequence.

By the same token, if the notes in the MIDI file do not go until the end of the file, I'd like to define the length of the loop and to insert a rest.

Unit tests and fixtures (example MIDI files) included. To run the tests:

UnitTest.runTestClassForClass(SimpleMIDIFile);

The post window should show:

RUNNING UNIT TEST 'TestSimpleMIDIFile'
PASS: a TestSimpleMIDIFile: test_generatePatternSeqs_withVelocity
Is:
         [ [ 60, 1.0, 0.59055118110236 ], [ rest, 1.0, 0.0 ], [ 60, 1.0, 0.78740157480315 ] ]
Should be:
         [ [ 60, 1.0, 0.59055118110236 ], [ rest, 1.0, 0.0 ], [ 60, 1.0, 0.78740157480315 ] ]
PASS: a TestSimpleMIDIFile: test_generatePatternSeqs_noPaddingBeginningStart
Is:
         [ [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ] ]
Should be:
         [ [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ] ]
PASS: a TestSimpleMIDIFile: test_generatePatternSeqs_noPaddingOffsetStart
Is:
         [ [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ] ]
Should be:
         [ [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ] ]
PASS: a TestSimpleMIDIFile: test_generatePatternSeqs_padStart
Is:
         [ [ rest, 1.0 ], [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ] ]
Should be:
         [ [ rest, 1.0 ], [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ] ]
PASS: a TestSimpleMIDIFile: test_generatePatternSeqs_padEnd
Is:
         [ [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ], [ rest, 1.0 ] ]
Should be:
         [ [ 60, 1.0 ], [ rest, 1.0 ], [ 60, 1.0 ], [ rest, 1.0 ] ]

UNIT TESTS FOR 'TestSimpleMIDIFile' COMPLETED
There were no failures

[60, 1.0, 75/127.0],
[\rest, 1.0, 0.0],
[60, 1.0, 100/127.0]
]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3-tuple when velocity flag is set.

[60, 1.0],
[\rest, 1.0],
[60, 1.0]
]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default / previous behavior.

[60, 1.0],
[\rest, 1.0],
[60, 1.0]
]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default / previous behavior.

[60, 1.0],
[\rest, 1.0],
[60, 1.0]
]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pads the start of the pattern with a rest, because the first note is a beat in.

[\rest, 1.0],
[60, 1.0],
[\rest, 1.0]
]);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pads the end of the pattern with a rest, because the last note ends at 3.0 and the argument is 4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant