musical_games.converters package¶
Submodules¶
musical_games.converters.audio module¶
-
class
musical_games.converters.audio.
FluidSynth
(sound_font, gain=None)[source]¶ Bases:
musical_games.converters.audio.MidiToWav
Create a new converter to convert midi to wav.
Parameters: - sound_font (str) – the path to the sound font to use.
- gain (float) – number between 0 and 1 to indicate the desired output gain.
-
class
musical_games.converters.audio.
MidiToWav
(sound_font, gain=None)[source]¶ Bases:
object
Create a new converter to convert midi to wav.
Parameters: - sound_font (str) – the path to the sound font to use.
- gain (float) – number between 0 and 1 to indicate the desired output gain.
-
class
musical_games.converters.audio.
Timidity
(sound_font, gain=None)[source]¶ Bases:
musical_games.converters.audio.MidiToWav
Create a new converter to convert midi to wav.
Parameters: - sound_font (str) – the path to the sound font to use.
- gain (float) – number between 0 and 1 to indicate the desired output gain.
-
class
musical_games.converters.audio.
WavConverter
[source]¶ Bases:
object
Converter for converting wav to any other media format.
-
is_available
()[source]¶ Check if the implementing method is available.
Returns: if this method is available Return type: bool
-
-
musical_games.converters.audio.
midi_to_wav
(midi_fname, wav_fname, sound_font, gain=None)[source]¶ Tries to autodetect the available midi converter and uses the best one found.
Parameters: - midi_fname (str) – the location of the midi file
- wav_fname (str) – where to place the output wav file.
- sound_font (str) – the path to the sound font file.
- gain (float) – number between 0 and 1 to indicate the desired output gain.
musical_games.converters.images module¶
-
musical_games.converters.images.
concatenate_images
(output_fname, image_list)[source]¶ Append all the given files to each other in the order given.
Parameters: - output_fname (str) – the output filename
- image_list (list of str) – the filenames of the images to append
-
musical_games.converters.images.
draw_rectangle
(image_fname, fill_color, stroke_color, stroke_width, position, end_position, output_fname=None)[source]¶ Draw a rectangle on a given image.
Parameters: - image_fname – the image to draw on
- fill_color (str) – the imagemagick color to use for filling
- stroke_color (str) – the imagemagick color for the border
- stroke_width (int) – the width fo the stroke
- position (tuple) – the x,y position of the top-left of the rectangle
- end_position (tuple) – the x,y end position of the rectangle to draw
- output_fname – the output image, if not set it defaults to the input image
musical_games.converters.lilypond module¶
-
class
musical_games.converters.lilypond.
TypesetResults
(pdf_list, png_list, ps_list, midi_list)[source]¶ Bases:
object
Result set for the output of the lilypond function.
Parameters: - pdf_list (list of str) – the locations of the output pdf files
- png_list (list of str) – the locations of the png files
- ps_list (list of str) – the locations of the ps files
- midi_list (list of str) – the locations of the midi files
-
musical_games.converters.lilypond.
lilypond
(lilypond_fname, output, pdf=True, png=True, ps=False)[source]¶ Typeset music and/or produce midi from file.
This runs the shell command lilypond to on the inputs. Note that Midi output needs to be defined in the lilypond file and can not be set on the command line.
Parameters: - lilypond_fname (str) – the location of the lilypond file to convert.
- output (str) – the location for the output files, suffixes will be added.
- pdf (str) – if we want pdf output
- png (boolean) – if we want png output
- ps (boolean) – if we want postscript output
Raises: RuntimeError
– if the compilation of the lilypond file failed somehow.Returns: the result set with the location of the output files.
Return type:
musical_games.converters.utils module¶
-
musical_games.converters.utils.
bash_function_exists
(function_name)[source]¶ Check if the bash function with the given name exists.
Runs the command ‘which <function_name>’ to check if the function exists.
Parameters: function_name (str) – the function name to check for existence Returns: if the command exists Return type: boolean
-
musical_games.converters.utils.
ensure_dir_exists
(file_path)[source]¶ Ensures that the dir to the given file exists.
Normally used when writing output to a file to make sure the directories exist.
Parameters: file_path (str) – the path to a file.
-
musical_games.converters.utils.
remove_file_if_exists
(file_path)[source]¶ Remove the given file if it exists.
Parameters: file_path (str) – the path to a file.
-
musical_games.converters.utils.
run_command
(command, shell=False)[source]¶ Run a shell command.
Parameters: - command (str or list) – the shell command to run
- shell (bool) – the subprocess flag for shell
Raises: RuntimeError
– if the command returned with exit code -1Returns: the stdout of the command
Return type: str