当前位置: 首页>>代码示例>>Python>>正文


Python librosa.note_to_midi方法代码示例

本文整理汇总了Python中librosa.note_to_midi方法的典型用法代码示例。如果您正苦于以下问题:Python librosa.note_to_midi方法的具体用法?Python librosa.note_to_midi怎么用?Python librosa.note_to_midi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在librosa的用法示例。


在下文中一共展示了librosa.note_to_midi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: enharmonic

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def enharmonic(self, key_str):
        '''Force the tonic spelling to fit our tonic list 
        by spelling out of vocab keys enharmonically.

        Parameters
        ----------
        key_str : str
            The key_mode string in jams style.

        Returns
        -------
        key_str : str
            The key_mode string spelled enharmonically to fit our vocab.
        '''
        key_list = key_str.split(':')
        # spell the tonic enharmonically if necessary
        if key_list[0] != 'N':
            key_list[0] = midi_to_note(note_to_midi(key_list[0]), octave=False)
            if len(key_list) == 1:
                key_list.append('major')

        return ':'.join(key_list) 
开发者ID:bmcfee,项目名称:pumpp,代码行数:24,代码来源:key.py

示例2: testBeams_sixteenthNotes

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testBeams_sixteenthNotes(self):
    filename = os.path.join(resource_loader.get_data_files_path(),
                            'testdata/IMSLP00747-000.png')
    notes = self.engine.run([filename], output_notesequence=True)

    def _sixteenth_note(pitch, start_time):
      return music_pb2.NoteSequence.Note(
          pitch=librosa.note_to_midi(pitch),
          start_time=start_time,
          end_time=start_time + 0.25)

    # TODO(ringw): Fix the phantom quarter note detected before the treble
    # clef, and the eighth rest before the first note (should be sixteenth).
    self.assertIn(_sixteenth_note('C4', 1.5), notes.notes)
    self.assertIn(_sixteenth_note('D4', 1.75), notes.notes)
    self.assertIn(_sixteenth_note('E4', 2), notes.notes)
    self.assertIn(_sixteenth_note('F4', 2.25), notes.notes)
    # TODO(ringw): The second D and E are detected with only one beam, even
    # though they are connected to the same beams as the F before them and the
    # C after them. Fix. 
开发者ID:tensorflow,项目名称:moonlight,代码行数:22,代码来源:omr_endtoend_test.py

示例3: _key_sig_pitch_classes

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def _key_sig_pitch_classes(note_name, ascending_fifths):
  first_pitch_class = (
      librosa.note_to_midi(note_name + '0') %
      constants.NUM_SEMITONES_PER_OCTAVE)
  # Go through the circle of fifths in ascending or descending order.
  step = 1 if ascending_fifths else -1
  order = constants.CIRCLE_OF_FIFTHS[::step]
  # Get the start index for the key signature.
  first_pitch_class_ind = order.index(first_pitch_class)
  return list(
      itertools.islice(
          # Create a cycle of the order. We may loop around, e.g. from F back to
          # C.
          itertools.cycle(order),
          # Take the 7 pitch classes from the cycle.
          first_pitch_class_ind,
          first_pitch_class_ind + constants.NUM_NOTES_IN_DIATONIC_SCALE)) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:19,代码来源:key_signature.py

示例4: testTreble_simple

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testTreble_simple(self):
    staff = musicscore_pb2.Staff(
        staffline_distance=10,
        center_line=[Point(x=0, y=50), Point(x=100, y=50)],
        glyph=[
            Glyph(
                type=Glyph.CLEF_TREBLE,
                x=1,
                y_position=reader.TREBLE_CLEF_EXPECTED_Y),
            Glyph(type=Glyph.NOTEHEAD_FILLED, x=10, y_position=0),
        ])
    notes = conversions.page_to_notesequence(reader.ScoreReader().read_page(
        musicscore_pb2.Page(system=[musicscore_pb2.StaffSystem(
            staff=[staff])])))
    self.assertEqual(
        notes,
        music_pb2.NoteSequence(notes=[
            Note(pitch=librosa.note_to_midi('B4'), start_time=0, end_time=1)
        ])) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:21,代码来源:reader_test.py

示例5: testBass_simple

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testBass_simple(self):
    staff = musicscore_pb2.Staff(
        staffline_distance=10,
        center_line=[Point(x=0, y=50), Point(x=100, y=50)],
        glyph=[
            Glyph(
                type=Glyph.CLEF_BASS,
                x=1,
                y_position=reader.BASS_CLEF_EXPECTED_Y),
            Glyph(type=Glyph.NOTEHEAD_FILLED, x=10, y_position=0),
        ])
    notes = conversions.page_to_notesequence(reader.ScoreReader().read_page(
        musicscore_pb2.Page(system=[musicscore_pb2.StaffSystem(
            staff=[staff])])))
    self.assertEqual(
        notes,
        music_pb2.NoteSequence(notes=[
            Note(pitch=librosa.note_to_midi('D3'), start_time=0, end_time=1)
        ])) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:21,代码来源:reader_test.py

示例6: testAllNoteheadTypes

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testAllNoteheadTypes(self):
    staff = musicscore_pb2.Staff(
        staffline_distance=10,
        center_line=[Point(x=0, y=50), Point(x=100, y=50)],
        glyph=[
            Glyph(
                type=Glyph.CLEF_TREBLE,
                x=1,
                y_position=reader.TREBLE_CLEF_EXPECTED_Y),
            Glyph(type=Glyph.NOTEHEAD_FILLED, x=10, y_position=-6),
            Glyph(type=Glyph.NOTEHEAD_EMPTY, x=10, y_position=-6),
            Glyph(type=Glyph.NOTEHEAD_WHOLE, x=10, y_position=-6),
        ])
    notes = conversions.page_to_notesequence(reader.ScoreReader().read_page(
        musicscore_pb2.Page(system=[musicscore_pb2.StaffSystem(
            staff=[staff])])))
    self.assertEqual(
        notes,
        music_pb2.NoteSequence(notes=[
            Note(pitch=librosa.note_to_midi('C4'), start_time=0, end_time=1),
            Note(pitch=librosa.note_to_midi('C4'), start_time=1, end_time=3),
            Note(pitch=librosa.note_to_midi('C4'), start_time=3, end_time=7),
        ])) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:25,代码来源:reader_test.py

示例7: testEndToEnd

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testEndToEnd(self):
    with tempfile.TemporaryDirectory() as tmpdir:
      with engine.get_included_labels_file() as centroids:
        export_dir = os.path.join(tmpdir, 'export')
        export_kmeans_centroids.run(centroids.name, export_dir)

      # Now load the saved model.
      omr = engine.OMREngine(
          glyph_classifier_fn=saved_classifier.SavedConvolutional1DClassifier
          .glyph_classifier_fn(export_dir))
      filename = os.path.join(tf.resource_loader.get_data_files_path(),
                              '../testdata/IMSLP00747-000.png')
      notes = omr.run(filename, output_notesequence=True)
      # TODO(ringw): Fix the extra note that is detected before the actual
      # first eighth note.
      self.assertEqual(librosa.note_to_midi('C4'), notes.notes[1].pitch)
      self.assertEqual(librosa.note_to_midi('D4'), notes.notes[2].pitch)
      self.assertEqual(librosa.note_to_midi('E4'), notes.notes[3].pitch) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:20,代码来源:export_kmeans_centroids_test.py

示例8: gen_onsets_info_from_label_v1

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def gen_onsets_info_from_label_v1(label, inst_num=1, t_unit=0.02):
    intervals = []
    pitches = []

    onsets = {}
    lowest_pitch = librosa.note_to_midi("A0")
    for t, ll in enumerate(label):
        for pitch, insts in ll.items():
            if inst_num not in insts:
                continue
            if (pitch not in onsets) or (insts[inst_num][0] > onsets[pitch]):
                intervals.append([t*t_unit, (t+2)*t_unit])
                pitches.append(librosa.midi_to_hz(lowest_pitch+pitch))
            onsets[pitch] = insts[inst_num][0]

    return np.array(intervals), np.array(pitches) 
开发者ID:BreezeWhite,项目名称:Music-Transcription-with-Semantic-Segmentation,代码行数:18,代码来源:eval_utils.py

示例9: to_midi

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def to_midi(notes, t_unit=0.02):
    midi = pretty_midi.PrettyMIDI()
    piano = pretty_midi.Instrument(program=0)
    
    
    l, u = find_min_max_stren(notes)
    s_low = 60
    s_up = 127
    v_map = lambda stren: int(s_low+((s_up-s_low)*((stren-l)/(u-l+0.0001))))
    
    low_b = note_to_midi("A0")
    coll = set()
    for nn in notes:
        pitch = nn["pitch"] + low_b
        start = nn["start"] * t_unit
        end = nn["end"] * t_unit
        volume = v_map(nn["stren"])
        coll.add(pitch)
        m_note = pretty_midi.Note(velocity=volume, pitch=pitch, start=start, end=end)
        piano.notes.append(m_note)
    midi.instruments.append(piano)
    return midi 
开发者ID:BreezeWhite,项目名称:Music-Transcription-with-Semantic-Segmentation,代码行数:24,代码来源:postprocess.py

示例10: testNoteSequence

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testNoteSequence(self):
    filename = os.path.join(resource_loader.get_data_files_path(),
                            'testdata/IMSLP00747-000.png')
    notes = self.engine.run(filename, output_notesequence=True)
    # TODO(ringw): Fix the extra note that is detected before the actual
    # first eighth note.
    self.assertEqual(librosa.note_to_midi('C4'), notes.notes[1].pitch)
    self.assertEqual(librosa.note_to_midi('D4'), notes.notes[2].pitch)
    self.assertEqual(librosa.note_to_midi('E4'), notes.notes[3].pitch)
    self.assertEqual(librosa.note_to_midi('F4'), notes.notes[4].pitch)
    self.assertEqual(librosa.note_to_midi('D4'), notes.notes[5].pitch)
    self.assertEqual(librosa.note_to_midi('E4'), notes.notes[6].pitch)
    self.assertEqual(librosa.note_to_midi('C4'), notes.notes[7].pitch) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:15,代码来源:omr_endtoend_test.py

示例11: testTrebleClef

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testTrebleClef(self):
    self.assertEqual(clef.TrebleClef().y_position_to_midi(-8),
                     librosa.note_to_midi('A3'))
    self.assertEqual(clef.TrebleClef().y_position_to_midi(-6),
                     librosa.note_to_midi('C4'))
    self.assertEqual(clef.TrebleClef().y_position_to_midi(0),
                     librosa.note_to_midi('B4'))
    self.assertEqual(clef.TrebleClef().y_position_to_midi(1),
                     librosa.note_to_midi('C5'))
    self.assertEqual(clef.TrebleClef().y_position_to_midi(3),
                     librosa.note_to_midi('E5'))
    self.assertEqual(clef.TrebleClef().y_position_to_midi(4),
                     librosa.note_to_midi('F5'))
    self.assertEqual(clef.TrebleClef().y_position_to_midi(14),
                     librosa.note_to_midi('B6')) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:17,代码来源:clef_test.py

示例12: testBassClef

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def testBassClef(self):
    self.assertEqual(clef.BassClef().y_position_to_midi(-10),
                     librosa.note_to_midi('A1'))
    self.assertEqual(clef.BassClef().y_position_to_midi(-7),
                     librosa.note_to_midi('D2'))
    self.assertEqual(clef.BassClef().y_position_to_midi(-5),
                     librosa.note_to_midi('F2'))
    self.assertEqual(clef.BassClef().y_position_to_midi(-1),
                     librosa.note_to_midi('C3'))
    self.assertEqual(clef.BassClef().y_position_to_midi(0),
                     librosa.note_to_midi('D3'))
    self.assertEqual(clef.BassClef().y_position_to_midi(6),
                     librosa.note_to_midi('C4'))
    self.assertEqual(clef.BassClef().y_position_to_midi(8),
                     librosa.note_to_midi('E4')) 
开发者ID:tensorflow,项目名称:moonlight,代码行数:17,代码来源:clef_test.py

示例13: __init__

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def __init__(self):
    self.center_line_pitch = _ScalePitch(constants.MAJOR_SCALE,
                                         librosa.note_to_midi('D3'))
    self.glyph = musicscore_pb2.Glyph.CLEF_BASS 
开发者ID:tensorflow,项目名称:moonlight,代码行数:6,代码来源:clef.py

示例14: gen_onsets_info

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def gen_onsets_info(data, t_unit=0.02):
    #logging.debug("Data shape: %s", data.shape)
    pitches   = []
    intervals = []
    lowest_pitch = librosa.note_to_midi("A0")

    for i in range(data.shape[1]):
        notes = find_occur(data[:, i], t_unit=t_unit)
        it = []
        for nn in notes:
            it.append([nn["onset"]*t_unit, nn["offset"]*t_unit])
        
        if len(intervals)==0 and len(it) > 0:
            intervals = np.array(it)
        elif len(it) > 0:
            intervals = np.concatenate((intervals, np.array(it)), axis=0)
            
        # hz = CentralFrequency[i]
        hz = librosa.midi_to_hz(lowest_pitch+i)
        for i in range(len(it)):
            pitches.append(hz)
    
    if type(intervals) == list:
        intervals = np.array([]).reshape((0, 2))
    pitches = np.array(pitches)
    
    return intervals, pitches 
开发者ID:BreezeWhite,项目名称:Music-Transcription-with-Semantic-Segmentation,代码行数:29,代码来源:eval_utils.py

示例15: gen_frame_info_from_notes

# 需要导入模块: import librosa [as 别名]
# 或者: from librosa import note_to_midi [as 别名]
def gen_frame_info_from_notes(midi_notes, t_unit=0.02):
    tmp_midi = pretty_midi.PrettyMIDI()
    inst = pretty_midi.Instrument(program=0)
    inst.notes += midi_notes
    tmp_midi.instruments.append(inst)
    piano_roll = tmp_midi.get_piano_roll(fs=round(1/t_unit)).transpose()
    low = librosa.note_to_midi("A0")
    hi = librosa.note_to_midi("C8")+1
    piano_roll = piano_roll[:, low:hi]

    return gen_frame_info(piano_roll, t_unit=t_unit) 
开发者ID:BreezeWhite,项目名称:Music-Transcription-with-Semantic-Segmentation,代码行数:13,代码来源:eval_utils.py


注:本文中的librosa.note_to_midi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。