musical_games.converters package

Submodules

musical_games.converters.audio module

class musical_games.converters.audio.AVConv[source]

Bases: musical_games.converters.audio.FFMpegLike

class musical_games.converters.audio.FFMpeg[source]

Bases: musical_games.converters.audio.FFMpegLike

class musical_games.converters.audio.FFMpegLike(command_name)[source]

Bases: musical_games.converters.audio.WavConverter

is_available()[source]
to_mp3(wav_fname, output_fname)[source]
to_ogg(wav_fname, output_fname)[source]
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.
convert(midi_fname, wav_fname)[source]
is_available()[source]
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.
convert(midi_fname, wav_fname)[source]

Convert the given midi file to a wav file at the given location.

Parameters:
  • midi_fname (str) – the location of the midi file
  • wav_fname (str) – where to place the output wav file.
is_available()[source]

Check if the implementing method is available.

Returns:if this method is available
Return type:bool
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.
convert(midi_fname, wav_fname)[source]
is_available()[source]
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
to_mp3(wav_fname, output_fname)[source]

Convert the given wav file to an mp3 file.

Parameters:
  • wav_fname (str) – the wav filename
  • output_fname (str) – the output file
to_ogg(wav_fname, output_fname)[source]

Convert the given wav file to an ogg file.

Parameters:
  • wav_fname (str) – the wav filename
  • output_fname (str) – the output file
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.audio.wav_to_mp3(wav_fname, mp3_fname)[source]

Tries to autodetect the available wav converter and uses the best one found.

Parameters:
  • wav_fname (str) – where to place the output wav file.
  • mp3_fname (str) – the path to the output mp3 file
musical_games.converters.audio.wav_to_ogg(wav_fname, ogg_fname)[source]

Tries to autodetect the available wav converter and uses the best one found.

Parameters:
  • wav_fname (str) – where to place the output wav file.
  • ogg_fname (str) – the path to the output mp3 file

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.images.get_image_size(image_fname)[source]

Get the size of the given image.

Parameters:image_fname (str) – the image we want to get the width and height of
Returns:width, height of the given image
Return type:tuple
musical_games.converters.images.trim_image(image_fname, output_fname=None)[source]

Trim the given images.

Parameters:
  • image_fname – the image to trim
  • output_fname – the output image, if not set it defaults to the input image
Returns:

the name of the output image

Return type:

str

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:

TypesetResults

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 -1

Returns:

the stdout of the command

Return type:

str

Module contents