musicflower.webapp.WebApp
- class musicflower.webapp.WebApp(verbose=False)[source]
Bases:
object
Public Data Attributes:
Public Methods:
__init__
([verbose])init
([title, update_title, ...])check_features
(features[, n, asfarray])update_figure_layout
(figure, **kwargs)position_idx
(position, *[, n, features])For a position in [0, 1] and features of length n, compute the corresponding index in {0, ..., n - 1}.
use_chroma_features
([n, name])use_chroma_scape_features
([name, chroma_name])use_fourier_features
([name, chroma_name])use_fourier_scape_features
([name, chroma_name])register_feature_extractor
(name, func)Register a feature extractor with given name that computes features from an audio file.
register_feature_remapper
(remapper_name, ...)Register a feature remapper with given name that remaps the input features to a new set of features.
register_visualiser
(visualiser_name, ...[, ...])Register a visualiser with given name that generates plots from the input features.
run
(*args, **kwargs)Private Methods:
_register
(key, value, registry, msg_name)_duplicate_name_check
(name)_unpack_visualiser_args
(*args)_file_like_from_upload_content
(content)_setup_layout
(title, update_title, ...[, ...])_setup_audio_position_sync
(sync_interval_ms, ...)_audio_element
(audio_file[, audio_src])
- __annotations__ = {}
- __dict__ = mappingproxy({'__module__': 'musicflower.webapp', 'major_minor_profiles': array([[[0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 ], [0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 ], [0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 ], [0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 ], [0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 ], [0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 ], [0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 ], [0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 ], [0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 ], [0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 ], [0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 ], [0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 ]], [[0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421], [0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224], [0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409], [0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425], [0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886], [0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405], [0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641], [0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808], [0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649], [0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842], [0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202], [0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088]]]), '__init__': <function WebApp.__init__>, 'init': <function WebApp.init>, 'check_features': <classmethod(<function WebApp.check_features>)>, 'update_figure_layout': <classmethod(<function WebApp.update_figure_layout>)>, 'position_idx': <classmethod(<function WebApp.position_idx>)>, 'use_chroma_features': <function WebApp.use_chroma_features>, 'use_chroma_scape_features': <function WebApp.use_chroma_scape_features>, 'use_fourier_features': <function WebApp.use_fourier_features>, 'use_fourier_scape_features': <function WebApp.use_fourier_scape_features>, 'register_feature_extractor': <function WebApp.register_feature_extractor>, 'register_feature_remapper': <function WebApp.register_feature_remapper>, 'register_visualiser': <function WebApp.register_visualiser>, '_register': <function WebApp._register>, '_duplicate_name_check': <function WebApp._duplicate_name_check>, '_init_feature_extractor_callbacks': <function WebApp._init_feature_extractor_callbacks>, '_init_feature_remapper_callbacks': <function WebApp._init_feature_remapper_callbacks>, '_init_visualiser_callbacks': <function WebApp._init_visualiser_callbacks>, '_unpack_visualiser_args': <function WebApp._unpack_visualiser_args>, '_file_like_from_upload_content': <classmethod(<function WebApp._file_like_from_upload_content>)>, '_setup_layout': <function WebApp._setup_layout>, '_setup_audio_position_sync': <function WebApp._setup_audio_position_sync>, '_audio_element': <function WebApp._audio_element>, 'run': <function WebApp.run>, '__dict__': <attribute '__dict__' of 'WebApp' objects>, '__weakref__': <attribute '__weakref__' of 'WebApp' objects>, '__doc__': None, '__annotations__': {}})
- __module__ = 'musicflower.webapp'
- __weakref__
list of weak references to the object (if defined)
- _setup_layout(title, update_title, idle_interval_ms, audio_file, external_stylesheets, name, figure_width, figure_height, dash_kwargs=())[source]
- init(title='MusicFlower', update_title=None, sync_interval_ms=50, idle_interval_ms=1000, n_sync_before_idle=10, audio_file=None, external_stylesheets=(), name=None, suppress_flask_logger=True, figure_width=None, figure_height=None, _debug_display_toggles=False, dash_kwargs=())[source]
- Parameters:
title
update_title
sync_interval_ms
idle_interval_ms
n_sync_before_idle
audio_file
external_stylesheets
name
suppress_flask_logger – suppress extensive logging, only show errors
figure_width
figure_height
_debug_display_toggles
dash_kwargs
- Returns:
- major_minor_profiles = array([[[0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 ], [0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 ], [0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 ], [0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 ], [0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 ], [0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 ], [0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 , 0.094 ], [0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 , 0.137 ], [0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 , 0.006 ], [0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 , 0.111 ], [0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 , 0.006 ], [0.006 , 0.111 , 0.006 , 0.137 , 0.094 , 0.016 , 0.214 , 0.009 , 0.08 , 0.008 , 0.081 , 0.238 ]], [[0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421], [0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224], [0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409], [0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425], [0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886], [0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405], [0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641], [0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649, 0.01903808], [0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842, 0.12324649], [0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202, 0.10420842], [0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088, 0.00601202], [0.00601202, 0.10420842, 0.12324649, 0.01903808, 0.10320641, 0.01202405, 0.21442886, 0.06212425, 0.02204409, 0.06112224, 0.05210421, 0.22044088]]])
- classmethod position_idx(position, *, n=None, features=None)[source]
For a position in [0, 1] and features of length n, compute the corresponding index in {0, …, n - 1}.
- Parameters:
position – number in [0, 1]
n – length of features
features – features to compute n as len(features)
- Returns:
index
- register_feature_extractor(name, func)[source]
Register a feature extractor with given name that computes features from an audio file. The returned features are converted to json and stored on the client side. They can be reused by feature remappers.
- Parameters:
name – unique name of this feature extractor
func – a callable that takes one ‘audio’ key-word argument (containing the audio content as a BytesIO object, i.e., as if the audio file had been opened using open ) and returns the extracted features in a format that can be converted to json (e.g. nested lists)
- register_feature_remapper(remapper_name, feature_names, func)[source]
Register a feature remapper with given name that remaps the input features to a new set of features. Input features are retrieved from the client side in json format, so only basic data types are available (e.g. arrays are stored as lists).
- Parameters:
remapper_name – unique name of this feature remapper
feature_names – iterable with names of the input features to be used
func – a callable that takes one ‘features’ key-word argument (containing the input features) and returns the new feature in a format that can be converted to json (e.g. nested lists)
- register_visualiser(visualiser_name, feature_names, func, update=False)[source]
Register a visualiser with given name that generates plots from the input features. Feature values are retrieved from the client side in json format, so only basic data types are available (e.g. arrays are stored as lists).
- Parameters:
visualiser_name – unique name of this visualiser
feature_names – iterable with names of the input features to be used
func – a callable that takes two key-word arguments, ‘features’ and ‘position’, (containing the input features and the current normalised audio position in the interval [0, 1]) and returns a figure (or dict, depending on ‘update’)
update – this argument can be used to avoid expensive computations that only need to be done once when the figure is set up. If ‘update’ is False (default), ‘func’ is expected to always return a complete Plotly figure at each call; if ‘update’ is True, ‘func’ should behave differently depending on whether the ‘position’ argument is None or a valid position: If ‘position’ is None, ‘func’ should return an entire Plotly figure, which is used to initialise the graph; if ‘position’ is not None (i.e. it is a valid position in [0, 1]), ‘func’ should return a list of dictionaries containing updates for the single traces of the existing figure, in particular, the ‘data’ entry of the existing figure is a list of dictionaries defining separate traces and each trace will be updated with the corresponding data returned by ‘func’ (using new_trace = { **old_trace, **update} so if a key exists in old_trace but not in update, the old values are retained). A typical use case would be to dynamically update the x/y location of a marker while keeping the background static. Importantly, in order to update a trace, it has to be present in the initial figure (possibly using empty coordinates, to avoid plotting anything). The number of returned dicts must be the same as in the number of traces in the initial figure (empty dicts should be used for traces that remain unchanged); also the layout is determined by the initial figure as only the trace data is modified.