Exemplo n.º 1
0
def test_FingeringNotation_02():
    event_a = modeltools.Event.objects.get(name='event__alto_saxophone__br_042.aif')
    fingering_a = event_a.fingering.get_compact_representation(
        event_a.fingering.key_names,
        event_a.fingering.instrument.key_names,
        )
    instrument_a = stringtools.to_snake_case(event_a.fingering.instrument.name)
    event_b = modeltools.Event.objects.get(name='event__alto_saxophone__br_123.aif')
    fingering_b = event_b.fingering.get_compact_representation(
        event_b.fingering.key_names,
        event_b.fingering.instrument.key_names,
        )
    instrument_b = stringtools.to_snake_case(event_b.fingering.instrument.name)
    analysis_a = assettools.FingeringNotation(event_a)
    analysis_b = assettools.FingeringNotation(event_b)
    assert analysis_a.path == os.path.join(
        sasha_configuration.get_media_path('scores'),
        'fingering__{}__{}__fingering.svg'.format(
            instrument_a,
            fingering_a,
            ),
        )
    assert analysis_b.path == os.path.join(
        sasha_configuration.get_media_path('scores'),
        'fingering__{}__{}__fingering.svg'.format(
            instrument_b,
            fingering_b,
            ),
        )
Exemplo n.º 2
0
 def _rename_interactively(self, extension=None, file_name_callback=None, force_lowercase=True):
     getter = self._io_manager._make_getter()
     getter.append_identifier("enter new package name", allow_spaces=True)
     new_package_name = getter._run()
     if self._session.is_backtracking or new_package_name is None:
         return
     new_package_name = stringtools.to_snake_case(new_package_name)
     base_name = os.path.basename(self._path)
     new_directory = self._path.replace(base_name, new_package_name)
     messages = []
     messages.append("will change ...")
     messages.append(" FROM: {}".format(self._path))
     messages.append("   TO: {}".format(new_directory))
     self._io_manager._display(messages)
     result = self._io_manager._confirm()
     if self._session.is_backtracking or not result:
         return
     self._rename(new_directory)
     if not os.path.exists(new_directory):
         return
     for directory_entry in os.listdir(new_directory):
         if directory_entry.endswith(".py"):
             path = os.path.join(new_directory, directory_entry)
             result = os.path.splitext(base_name)
             old_package_name, extension = result
             self._replace_in_file(path, old_package_name, new_package_name)
Exemplo n.º 3
0
 def _make_staff(
     self,
     name,
     clef,
     abbreviation=None,
     context_name=None,
     instrument=None,
     tag=None,
     voices=None,
     ):
     name = name.title()
     staff_name = '{} Staff'.format(name)
     context_name = context_name or staff_name
     context_name = context_name.replace(' ', '')
     abbreviation = abbreviation or name
     abbreviation = stringtools.to_snake_case(abbreviation)
     voices = voices or [self._make_voice(name, abbreviation=abbreviation)]
     staff = scoretools.Staff(
         voices,
         context_name=context_name,
         name=staff_name
         )
     if not isinstance(clef, indicatortools.Clef):
         clef = indicatortools.Clef(clef)
     attach(clef, staff)
     if tag:
         self._attach_tag(tag, staff)
     if instrument:
         assert isinstance(instrument, instrumenttools.Instrument)
         attach(instrument, staff)
     return staff
Exemplo n.º 4
0
 def make_single_wind_performer(
     abbreviation=None,
     clef=None,
     instrument=None,
     score_template=None,
     ):
     performer_group = ScoreTemplateManager.make_performer_group(
         instrument=instrument,
         label=stringtools.to_dash_case(instrument.instrument_name),
         )
     name = instrument.instrument_name.title()
     context_name = ScoreTemplateManager.make_staff_name(name)
     voice = scoretools.Voice(
         name='{} Voice'.format(name),
         )
     staff = scoretools.Staff(
         [voice],
         context_name=context_name,
         name='{} Staff'.format(name),
         )
     performer_group.append(staff)
     attach(clef, voice)
     abbreviation = abbreviation or \
         stringtools.to_snake_case(name)
     score_template._context_name_abbreviations[abbreviation] = voice.name
     return performer_group
Exemplo n.º 5
0
 def _make_voice(self, name, abbreviation=None, context_name=None):
     name = name.title()
     abbreviation = abbreviation or name
     abbreviation = stringtools.to_snake_case(abbreviation)
     voice_name = '{} Voice'.format(name)
     voice = scoretools.Voice(
         name=voice_name,
         context_name=context_name,
         )
     self._register_abbreviation(abbreviation, voice)
     return voice
Exemplo n.º 6
0
    def from_expr(cls, expr):
        r'''Convenience constructor for enumerations.

        Returns new enumeration item.
        '''
        if isinstance(expr, cls):
            return expr
        elif isinstance(expr, int):
            return cls(expr)
        elif isinstance(expr, str):
            expr = expr.strip()
            expr = stringtools.to_snake_case(expr) 
            expr = expr.upper()
            return cls[expr]
        elif expr is None:
            return cls(0)
        message = 'Cannot instantiate {} from {}.'.format(cls.__name__, expr)
        raise ValueError(message)
Exemplo n.º 7
0
    def from_expr(cls, expr):
        r"""Convenience constructor for enumerations.

        Returns new enumeration item.
        """
        if isinstance(expr, cls):
            return expr
        elif isinstance(expr, int):
            return cls(expr)
        elif isinstance(expr, str):
            expr = expr.strip()
            expr = stringtools.to_snake_case(expr)
            expr = expr.upper()
            return cls[expr]
        elif expr is None:
            return cls(0)
        message = "Cannot instantiate {} from {}.".format(cls.__name__, expr)
        raise ValueError(message)
Exemplo n.º 8
0
 def _rename_interactively(
     self,
     extension=None,
     file_name_callback=None,
     force_lowercase=True,
 ):
     getter = self._io_manager._make_getter()
     getter.append_identifier('enter new package name', allow_spaces=True)
     new_package_name = getter._run()
     if self._session.is_backtracking or new_package_name is None:
         return
     new_package_name = stringtools.to_snake_case(new_package_name)
     base_name = os.path.basename(self._path)
     new_directory = self._path.replace(
         base_name,
         new_package_name,
     )
     messages = []
     messages.append('will change ...')
     messages.append(' FROM: {}'.format(self._path))
     messages.append('   TO: {}'.format(new_directory))
     self._io_manager._display(messages)
     result = self._io_manager._confirm()
     if self._session.is_backtracking or not result:
         return
     self._rename(new_directory)
     if not os.path.exists(new_directory):
         return
     for directory_entry in os.listdir(new_directory):
         if directory_entry.endswith('.py'):
             path = os.path.join(new_directory, directory_entry)
             result = os.path.splitext(base_name)
             old_package_name, extension = result
             self._replace_in_file(
                 path,
                 old_package_name,
                 new_package_name,
             )
Exemplo n.º 9
0
 def get_fixtures(self, cls):
     from sasha import sasha_configuration
     cls_name = stringtools.to_snake_case(cls.__name__)
     fixtures_path = os.path.join(
         sasha_configuration.get_media_path('fixtures'),
         cls_name + 's',
         #cls.__tablename__,
         )
     fixture_file_names = os.listdir(fixtures_path)
     fixture_file_names = (
         _ for _ in fixture_file_names
         if _.startswith(cls_name) and _.endswith('.json')
         )
     fixture_file_paths = (
         os.path.join(fixtures_path, _)
         for _ in fixture_file_names
         )
     fixtures = []
     for fixture_file_path in fixture_file_paths:
         with open(fixture_file_path, 'r') as file_pointer:
             fixture = json.load(file_pointer)
         fixtures.append(fixture)
     return fixtures
Exemplo n.º 10
0
 def make_auxiliary_staff(
     primary_instrument=None,
     secondary_instrument=None,
     score_template=None,
     ):
     name = '{} {}'.format(
         primary_instrument.instrument_name.title(),
         secondary_instrument.instrument_name.title(),
         )
     voice = scoretools.Voice(
         name='{} Voice'.format(name),
         )
     context_name = ScoreTemplateManager.make_staff_name(
         secondary_instrument.instrument_name.title(),
         )
     staff = scoretools.Staff(
         [voice],
         name='{} Staff'.format(name),
         context_name=context_name,
         )
     abbreviation = stringtools.to_snake_case(name)
     score_template._context_name_abbreviations[abbreviation] = voice.name
     return staff
Exemplo n.º 11
0
 def snake_case_name(self):
     return stringtools.to_snake_case(self.name)
Exemplo n.º 12
0
 def make_single_string_performer(
     abbreviation=None,
     clef=None,
     instrument=None,
     score_template=None,
     split=True,
     ):
     performer_group = ScoreTemplateManager.make_performer_group(
         context_name='StringPerformerGroup',
         instrument=instrument,
         label=stringtools.to_dash_case(instrument.instrument_name),
         )
     name = instrument.instrument_name.title()
     abbreviation = abbreviation or \
         stringtools.to_snake_case(name)
     if split:
         right_hand_voice = scoretools.Voice(
             name='{} Bowing Voice'.format(name),
             )
         right_hand_staff = scoretools.Staff(
             [right_hand_voice],
             context_name='BowingStaff',
             name='{} Bowing Staff'.format(name),
             )
         left_hand_voice = scoretools.Voice(
             name='{} Fingering Voice'.format(name),
             )
         left_hand_staff = scoretools.Staff(
             [left_hand_voice],
             context_name='FingeringStaff',
             name='{} Fingering Staff'.format(name),
             )
         performer_group.append(right_hand_staff)
         performer_group.append(left_hand_staff)
         attach(clef, left_hand_staff)
         attach(indicatortools.Clef('percussion'), right_hand_staff)
         right_hand_abbreviation = '{}_rh'.format(abbreviation)
         left_hand_abbreviation = '{}_lh'.format(abbreviation)
         score_template._context_name_abbreviations.update({
             abbreviation: performer_group.name,
             right_hand_abbreviation: right_hand_voice.name,
             left_hand_abbreviation: left_hand_voice.name,
             })
         score_template._composite_context_pairs[abbreviation] = (
             right_hand_abbreviation,
             left_hand_abbreviation,
             )
     else:
         voice = scoretools.Voice(
             name='{} Voice'.format(name),
             )
         staff = scoretools.Staff(
             [voice],
             context_name='StringStaff',
             name='{} Staff'.format(name),
             )
         performer_group.append(staff)
         attach(clef, voice)
         score_template._context_name_abbreviations[abbreviation] = \
             voice.name
     return performer_group