<commit_before># -*- encoding: utf-8 -*-
import collections
import copy
import hashlib
from supriya.tools.servertools.ServerObjectProxy import ServerObjectProxy


class SynthDef(ServerObjectProxy):
    r'''A synth definition.

    ::

        >>> from supriya.tools import synthdeftools
        >>> from supriya.tools import ugentools
        >>> builder = synthdeftools.SynthDefBuilder(frequency=440)
        >>> sin_osc = ugentools.SinOsc.ar(frequency=builder['frequency'])
        >>> out = ugentools.Out.ar(bus=0, source=sin_osc)
        >>> builder.add_ugen(out)
        >>> synthdef = builder.build()

    ::

        >>> from supriya import servertools
        >>> server = servertools.Server().boot()

    ::

        >>> synthdef.allocate(server=server)

    ::

        >>> synthdef in server
        True

    ::

        >>> synthdef.free()

    ::

        >>> synthdef in server
        False

    ::

        >>> server.quit()
        <Server: offline>

    '''

    ### CLASS VARIABLES ###

    __slots__ = (
        '_compiled_ugen_graph',
        '_constants',
        '_name',
        '_parameters',
        '_ugens',
        )

    ### INITIALIZER ###

    def __init__(
        self,
        ugens,
        name=None,
        ):
        from supriya.tools import synthdeftools
        ServerObjectProxy.__init__(self)
        compiler = synthdeftools.SynthDefCompiler
        self._name = name
        ugens = copy.deepcopy(ugens)
        ugens = self._flatten_ugens(ugens)
        ugens = self._optimize_ugen_graph(ugens)
        ugens, parameters = self._extract_parameters(ugens)
        control_ugens, control_mapping = self._collect_controls(
            parameters,
            )
        self._parameters = tuple(control_mapping.keys())
        self._remap_controls(ugens, control_mapping)
        ugens = control_ugens + ugens
        ugens = self._sort_ugens_topologically(ugens)
        self._ugens = tuple(ugens)
        self._constants = self._collect_constants(self._ugens)
        self._compiled_ugen_graph = compiler.compile_ugen_graph(self)

    ### SPECIAL METHODS ###

    def __eq__(self, expr):
        if type(expr) != type(self):
            return False
        if expr.name != self.name:
            return False
        if expr._compiled_ugen_graph != self._compiled_ugen_graph:
            return False
        return True

    def __hash__(self):
        hash_values = (
            type(self),
            self._name,
            self._compiled_ugen_graph,
            )
        return hash(hash_values)

    def __str__(self):
        r'''Gets string representation of synth definition.

        ::

            >>> from supriya.tools import synthdeftools
            >>> from supriya.tools import ugentools

        ::

            >>> builder = synthdeftools.SynthDefBuilder()
            >>> sin_one = ugentools.SinOsc.ar()
            >>> sin_two = ugentools.SinOsc.ar(frequency=443)
            >>> sum = sin_one + sin_two
            >>> out = ugentools.Out.ar(bus=0, source=sum)
            >>> builder.add_ugen(out)
            >>> synthdef = builder.build(name='test')
<commit_msg>Added trivial SynthDef repr.<commit_after># -*- encoding: utf-8 -*-
import collections
import copy
import hashlib
from supriya.tools.servertools.ServerObjectProxy import ServerObjectProxy


class SynthDef(ServerObjectProxy):
    r'''A synth definition.

    ::

        >>> from supriya.tools import synthdeftools
        >>> from supriya.tools import ugentools
        >>> builder = synthdeftools.SynthDefBuilder(frequency=440)
        >>> sin_osc = ugentools.SinOsc.ar(frequency=builder['frequency'])
        >>> out = ugentools.Out.ar(bus=0, source=sin_osc)
        >>> builder.add_ugen(out)
        >>> synthdef = builder.build()

    ::

        >>> from supriya import servertools
        >>> server = servertools.Server().boot()

    ::

        >>> synthdef.allocate(server=server)

    ::

        >>> synthdef in server
        True

    ::

        >>> synthdef.free()

    ::

        >>> synthdef in server
        False

    ::

        >>> server.quit()
        <Server: offline>

    '''

    ### CLASS VARIABLES ###

    __slots__ = (
        '_compiled_ugen_graph',
        '_constants',
        '_name',
        '_parameters',
        '_ugens',
        )

    ### INITIALIZER ###

    def __init__(
        self,
        ugens,
        name=None,
        ):
        from supriya.tools import synthdeftools
        ServerObjectProxy.__init__(self)
        compiler = synthdeftools.SynthDefCompiler
        self._name = name
        ugens = copy.deepcopy(ugens)
        ugens = self._flatten_ugens(ugens)
        ugens = self._optimize_ugen_graph(ugens)
        ugens, parameters = self._extract_parameters(ugens)
        control_ugens, control_mapping = self._collect_controls(
            parameters,
            )
        self._parameters = tuple(control_mapping.keys())
        self._remap_controls(ugens, control_mapping)
        ugens = control_ugens + ugens
        ugens = self._sort_ugens_topologically(ugens)
        self._ugens = tuple(ugens)
        self._constants = self._collect_constants(self._ugens)
        self._compiled_ugen_graph = compiler.compile_ugen_graph(self)

    ### SPECIAL METHODS ###

    def __eq__(self, expr):
        if type(expr) != type(self):
            return False
        if expr.name != self.name:
            return False
        if expr._compiled_ugen_graph != self._compiled_ugen_graph:
            return False
        return True

    def __hash__(self):
        hash_values = (
            type(self),
            self._name,
            self._compiled_ugen_graph,
            )
        return hash(hash_values)

    def __repr__(self):
        return '<{}: {}>'.format(
            type(self).__name__,
            self.actual_name,
            )

    def __str__(self):
        r'''Gets string representation of synth definition.

        ::

            >>> from supriya.tools import synthdeftools
            >>> from supriya.tools import ugentools

        ::

            >>> builder = synthdeftools.SynthDefBuilder()
            >>> sin_one = ugentools.SinOsc.ar()
            >>> sin_two = ugentools.SinOsc.ar(frequency=443)
            >>> sum = sin_one + sin_two
            >>> out = ugentools.Out.ar(bus=0, source=sum)
            >>> builder.add_ugen(out)
            >>> synthdef = builder.build(name='test')

{'fraction_non_alphanumeric': 0.11230362420283092, 'fraction_numerical': 0.0027998133457769483, 'mean_word_length': 2.014533520862635, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 144, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2751902', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1827, 'n_words': 343}