Skip to content

Commit

Permalink
Merge pull request #3 from JosepJoestar/master
Browse files Browse the repository at this point in the history
Add path option in csv2midi
  • Loading branch information
timwedde committed Mar 18, 2019
2 parents 3375824 + 2a039a8 commit 75d2c2f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions py_midicsv/csvmidi.py
Expand Up @@ -11,17 +11,17 @@
COMMENT_DELIMITERS = ("#", ";")


def parse(file):
def parse(file, path=False):
"""Parses a CSV file into MIDI format.
Args:
file: A string giving the path to a file on disk or an open file-like object.
path: Indicates if first parameter is a file path (False) or data string (True)
Returns:
A Pattern() object containing the byte-representations as parsed from
the input file.
"""

if isinstance(file, str):
with open(file, "r") as f:
return parse(f)
Expand All @@ -46,4 +46,8 @@ def parse(file):
event = csv_to_midi_map[identifier](tr, time, identifier, line[3:])
track.append(event)
pattern.make_ticks_rel()

if path:
file.close()

return pattern

0 comments on commit 75d2c2f

Please sign in to comment.