Package: File Conversion (src.conversion)

Module: conversion.main.py

This module provides functionality to convert multiple music files from a user-selected folder to a user-selected format.

The main function in this module is convert_multiple_files_filetype(). This function allows the user to select a folder containing music files and choose a format to convert these files into. The function will then convert each file in the folder into the selected format. Any errors or issues encountered during the conversion process are logged to specific .xlsx files for easy tracking and debugging.

Other utility functions imported from the src.conversion.utils and src.utils.error_handling modules are used to handle various tasks such as creating log entries, selecting conversion formats and folders, displaying success rates, and handling exceptions.

Functions

  • convert_multiple_files_filetype: Convert multiple music files from a user-selected folder to a user-selected format.

Utilities:

  • ‘create_log_entry’: Used to create log entries in the .xlsx files for errors occurred during parsing and conversion.

  • ‘display_parseable_files_in_folder’: Displays all parsable music files in a selected folder.

  • ‘display_success_rate’: Calculates and displays the success rate of the conversion process.

  • ‘select_conversion_format’: Prompts the user to select a conversion format from the available options.

  • ‘select_folder’: Prompts the user to select a folder containing music files for conversion.

  • ‘handle_error’: Handles any exceptions that occur during the execution of the function and displays the error to the user.

iMaT.src.conversion.main.convert_multiple_files_filetype()[source]

Convert multiple music files from a user-selected folder to a user-selected format.

This function first lists all parsable music files in a user-selected folder. Then it prompts the user to select a conversion format from the available options. The function then attempts to convert each file to the selected format and saves them in a newly created directory. Any failures during the parsing and conversion processes are logged to respective .xlsx files.

Return type:

None

Raises:

Exception – Any exception that occurs during the execution of the function is handled and displayed to the user.

Note

The function can convert files to different formats based on the options provided by the music21 converter. The available options include ‘musicxml’, ‘midi’, ‘braille’, etc. Not all formats may be available for all files. If a conversion is not possible, an error will be logged.

Module: conversion.utils.py

A module to handle various utility tasks related to the music file conversion process.

This module provides functions for:

  • Retrieving a list of parsable music files in a specified directory.

  • Displaying a list of parsable music files in a specified directory.

  • Displaying the success rate of file conversion.

  • Interactively selecting a folder containing parsable music files through a GUI.

  • Providing a user interface to select a music file conversion format.

  • Adding a new entry to a .xlsx log file.

All of these functions are designed to be used in the conversion process, and exceptions raised during their execution are handled and displayed to the user.

Functions

  • ‘get_parsable_files_in_folder’: Retrieve a list of parsable music files in a given directory.

  • ‘display_parseable_files_in_folder’: Display a list of parsable music files in a given directory.

  • ‘display_success_rate’: Display the success rate of file conversion.

  • ‘select_folder’: Interactively select a folder containing parsable music files.

  • ‘select_conversion_format’: Provide a user interface to select a music file conversion format.

  • ‘create_log_entry’: Add a new entry to a .xlsx log file.

raises Exception::

Any exception that occurs during the execution of the function is handled and displayed to the user.

iMaT.src.conversion.utils.create_log_entry(list, list_path)[source]

Add a new entry to a .xlsx log file.

This function appends a new row to a specified .xlsx file. If the file does not exist, it creates a new one.

Parameters:
  • list (list) – The new row to be added to the .xlsx file. Each element in the list represents a cell in the row.

  • list_path (str) – The path of the .xlsx file.

Return type:

None

Raises:

Exception – Any exception that occurs during the execution of the function is handled and displayed to the user.

iMaT.src.conversion.utils.display_parseable_files_in_folder(folder_path)[source]

Displays a list of parsable music files in a given directory.

This function first retrieves a list of parsable music files in the given directory. It then displays these files to the user.

Parameters:

folder_path (str) – The path of the directory to check.

Returns:

A list of filenames of parsable music files.

Return type:

list

Raises:

Exception – Any exception that occurs during the execution of the function is handled and displayed to the user.

iMaT.src.conversion.utils.display_success_rate(files_status, num_converted, num_files)[source]

Displays the success rate of file conversion.

This function calculates the success rate of file conversion based on the total number of files and the number of successfully converted files. It then displays this information along with a list of file conversion statuses.

Parameters:
  • files_status (list) – A list of tuples where each tuple contains a file’s name and its conversion status.

  • num_converted (int) – The number of files that were successfully converted.

  • num_files (int) – The total number of files that were attempted to be converted.

Raises:

Exception – Any exception that occurs during the execution of the function is handled and displayed to the user.

iMaT.src.conversion.utils.get_parsable_files_in_folder(folder_path)[source]

Retrieve a list of parsable music files in a given directory.

This function checks a specified directory for files with parsable music file extensions. It lists all the files with these extensions.

Parameters:

folder_path (str) – The path of the directory to check.

Returns:

A list of filenames of parsable music files.

Return type:

list

Raises:

Exception – Any exception that occurs during the execution of the function is handled and displayed to the user.

iMaT.src.conversion.utils.select_conversion_format()[source]

Provides a user interface to select a music file conversion format.

This function displays a list of available music file conversion formats to the user and prompts them to select one. It continues to prompt the user until a valid selection is made.

Returns:

The file extension of the chosen conversion format.

Return type:

str

Raises:

Exception – Any exception that occurs during the execution of the function is handled and displayed to the user.

iMaT.src.conversion.utils.select_folder()[source]

Interactively select a folder containing parsable music files.

This function displays a GUI file dialog to the user to select a folder. It ensures that the selected folder contains at least one parsable music file of the supported types. The function loops until a valid folder is selected or the user cancels the operation. It also provides information to the user about the types of parsable music files and folder requirements.

Returns:

The path to the selected folder containing parsable music files. Returns None if the operation is cancelled.

Return type:

str

Raises:

Exception – Any exception that occurs during the execution of the function is handled and displayed to the user.