cuthbertLab / music21

music21 is a Toolkit for Computational Musicology
https://www.music21.org/
Other
2.11k stars 400 forks source link

Add creationflags=subprocess.CREATE_NO_WINDOW in line 204 of /lily/translate.py #1356

Open charlesneimog opened 2 years ago

charlesneimog commented 2 years ago

Motivation Hi,

I am working in one way to use music21 inside PureData, and on Windows OS I have a popup of the shell window without the flag Create_NO_Window in line 204 of /lily/translate.py. See the video (Shell appear in 14-5 seconds)

https://user-images.githubusercontent.com/31707161/183222844-e0f9a052-83a2-4ff5-85e2-62c2ad5cba6a.mp4

Feature summary

I'd like to ask if could be possible (at least on Windows) add the creationflags=subprocess.CREATE_NO_WINDOW in lily/translate.py.

Proposed implementation

with subprocess.Popen(command, stdout=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW) as proc:

Intent

It is already implemented. I think that is a small change and it will not generate problems!

Thanks!

mscuthbert commented 2 years ago

creationflags was added in 3.7 -- minimum python version is now 3.8 so that is not an impediment. will need to see what else this affects. It seems like it should never show a window on .write() but should on .show()

I'm unfamiliar with PD's Python integration (intrigued though) -- can you give a simple example in pure python where the behavior is not optimal?

charlesneimog commented 2 years ago

Hi, this is possible using the C API for Python, I am developing the py4pd, but there are other ways like py/pyext.

The python code is just this!

def generate_image(note_name):
    score = music21.note.Note(note_name)
    score.notehead = 'normal'
    score.duration.quarterLength = 4.0
    ly = score.write('lilypond', fp='temp.ly')
    return ly

Thank you!