<commit_before>from collections import defaultdict

import sf
from rv.api import Synth, m


def sin_generator(name):
    return m.Generator(waveform='sin', name=name, polyphony_ch=1)


class Synth(Synth):

    _forward_graph = None
    _reverse_graph = None
    _operator_names = None

    def __init__(self, algorithm=None, name='sf.fm.Synth', factories=None):
        super(Synth, self).__init__(module=m.MetaModule(name=name))
        self.algorithm = algorithm or sf.fm.PRESETS[1][0]
        if isinstance(factories, list):
            self.factories = factories
            while len(factories) < self.operator_count:
                factories.append(factories[-1])
        else:
            factories = sin_generator if not callable(factories) else factories
            self.factories = [factories] * self.operator_count
        self._build_note_input()
        self._build_operators()
        self._build_output_volume()
        self._connect_algorithm()
        self._connect_note_input()
        self.module.project.layout(factor=2)

    @property
    def forward_graph(self):
        if not self._forward_graph:
            graph = defaultdict(list)
            edges = [(src, dest) for src, dest in self.algorithm.split(' ')]
            for src, dest in edges:
                dest = src if dest == '-' else dest
                node = graph[src]
                if dest not in node:
                    graph[src].append(dest)
            self._forward_graph = graph
        return self._forward_graph

    @property
    def reverse_graph(self):
        if not self._reverse_graph:
            graph = defaultdict(list)
            edges = [(src, dest) for src, dest in self.algorithm.split(' ')]
            for src, dest in edges:
                dest = src if dest == '-' else dest
                node = graph[dest]
                if src not in node:
                    graph[dest].append(src)
            self._reverse_graph = graph
        return self._reverse_graph<commit_msg>Transition from PyGraphviz to NetworkX for module autolayout<commit_after>from collections import defaultdict

import sf
from rv.api import Synth, m


def sin_generator(name):
    return m.Generator(waveform='sin', name=name, polyphony_ch=1)


class Synth(Synth):

    _forward_graph = None
    _reverse_graph = None
    _operator_names = None

    def __init__(self, algorithm=None, name='sf.fm.Synth', factories=None):
        super(Synth, self).__init__(module=m.MetaModule(name=name))
        self.algorithm = algorithm or sf.fm.PRESETS[1][0]
        if isinstance(factories, list):
            self.factories = factories
            while len(factories) < self.operator_count:
                factories.append(factories[-1])
        else:
            factories = sin_generator if not callable(factories) else factories
            self.factories = [factories] * self.operator_count
        self._build_note_input()
        self._build_operators()
        self._build_output_volume()
        self._connect_algorithm()
        self._connect_note_input()
        self.module.project.layout()

    @property
    def forward_graph(self):
        if not self._forward_graph:
            graph = defaultdict(list)
            edges = [(src, dest) for src, dest in self.algorithm.split(' ')]
            for src, dest in edges:
                dest = src if dest == '-' else dest
                node = graph[src]
                if dest not in node:
                    graph[src].append(dest)
            self._forward_graph = graph
        return self._forward_graph

    @property
    def reverse_graph(self):
        if not self._reverse_graph:
            graph = defaultdict(list)
            edges = [(src, dest) for src, dest in self.algorithm.split(' ')]
            for src, dest in edges:
                dest = src if dest == '-' else dest
                node = graph[dest]
                if src not in node:
                    graph[dest].append(src)
            self._reverse_graph = graph
        return self._reverse_graph
{'fraction_non_alphanumeric': 0.09284476355533548, 'fraction_numerical': 0.0022282743253280515, 'mean_word_length': 2.069908814589666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6366688', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1089, 'n_words': 286}