Code Monkey home page Code Monkey logo

musicpy's Introduction

Hi, I'm Rainbow Dreamer, a programmer who enjoys desigining useful mathematics, statistics and music related libraries and softwares. I also make music in my spare time, here is my artist page: NetEase / SoundCloud.


Contact

Discord: Rainbow Dreamer#7122
Email: [email protected] / [email protected]
qq: 2180502841
qq discussion group: 364834221
Bilibili: Rainbow_Dreamer

Anurag's GitHub stats

Readme Card     Readme Card

Readme Card     Readme Card

Readme Card     Readme Card

Readme Card     Readme Card

Readme Card     Readme Card

musicpy's People

Contributors

jenniferkuo avatar kant avatar kianmeng avatar nkid00 avatar olemb avatar oxygen-dioxide avatar rainbow-dreamer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

musicpy's Issues

Can you provide a basic example of how to use the sampler

I'm trying to get started with the sampler. I'm finding it hard to get started, the information is here but it's a bit to complicated for someone who doesn't know this module. It would help if there was a very simple example. Ive spent the last couple of days trying to figure out how to start.

If I had an example that shows how to do the following, it would be much easier to start.

1 drum loaded as a WAV file with a very simple sequence.
I sf2 loaded with an explanation of how to load a specific preset
simple chord progression of the sF2
A short loop made from the 2 sequences.
Play the loop
Export the loop

🙏🏼🙏🏼

Note example

Could you give a simple example on your Wiki how to create a simple melody. It is not clear to me how to play a simple sequence of notes. I tried the only_notes function but get the same output. If I want to play notes without the cords how would you do this?

split_melody返回的note对象

你好,请问我在用.split_melody(mode='notes')函数分离得到的主旋律音符对象,我的note对象里的duration是float类型的,这个是秒为单位的还是wiki文档里写的以节为单位的呢?如果是以节为单位的,是以默认的480ticks_per_beat和4/4分音符计算的,还是按每首歌自己不同的情况计算的
Uploading image.png…

关于track类型与build函数的几个问题(可能是bug)

  1. 用build函数创建piece,传入track时,只有当所有的track都有名称track_name时,输出piece的音轨才有名称。如果输入的某个track没有名称,则其他音轨的名称在piece中丢失
    image
    查看了代码,发现是写死在代码里面的。

    musicpy/musicpy/musicpy.py

    Lines 3019 to 3020 in ead467d

    if all(i.track_name for i in tracks_list):
    track_names = [i.track_name for i in tracks_list]

    是故意这样设计的吗?
  2. build不支持将数量不确定的track构建为一个piece。例如,这些track不是由用户在代码中写入的,而是由其他文件转换过来的,存放在一个list中,只能用append一个一个加。(这个设计不是很pythonic,像numpy这样的库会要求用户将所有的track先装入一个list,再传入函数,例如build([track1,track2,track3]),而不是build(track1,track2,track3)
  3. build不支持track与列表形式混输

play函数在linux下不可用

play函数在linux下,会报错

In [8]: play(note('A',5))                                                                
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-e5677dd3da72> in <module>
----> 1 play(note('A',5))

~/.pyenv/versions/3.8.0/lib/python3.8/site-packages/musicpy/musicpy.py in play(chord1, tempo, track, channel, time1, track_num, name, modes)
    198                  track_num=1,
    199                  mode=modes)
--> 200     os.startfile(f'{name}.mid')
    201 
    202 

AttributeError: module 'os' has no attribute 'startfile'

但是在当前目录生成了个 temp.mid 能够播放。目测是 linux下的python没有 os.startfile 这个函数,仅仅windows才有,希望跨平台适配。

音符滑音颤音功能

比如增加滑音颤音的参数,接收lambda表达式(传入根据音符回放时间变化的量)或者数值

Couldn't open /etc/timidity/freepats.cfg

Arch 下用 pip 安装, python 3.9 ,使用 play 函数就这样,
代码如下:

from musicpy import *
a = note('A', 5)
play(a)

报错:

/usr/lib/python3.9/site-packages/musicpy/musicpy.py in play(chord1, tempo, track, channel, time1, track_num, name, modes, instrument, i, save_as_file, deinterleave)
    235     if save_as_file:
    236         result_file = name
--> 237         pygame.mixer.music.load(result_file)
    238         pygame.mixer.music.play()
    239     else:

error: Couldn't open /etc/timidity/freepats.cfg

经过检查 /etc/timidity 这个目录没有,个人觉得这些文件可以直接放在包下的。

Unable to set volume for tracks

When using this code from the github example, I was unable to set the 'volume' argument for tracks.
new_piece = build(track(A1, instrument='Acoustic Grand Piano', start_time=0, channel=1, track_name='piano'))
This works, as does setting volume= for new_piece.
new_piece = build(track(A1, instrument='Acoustic Grand Piano', start_time=0, channel=1, track_name='piano',volume=40))
The error came up when using the 'play' method

  File "C:\Users\vlign\AppData\Local\Programs\Python\Python310\lib\site-packages\musicpy\musicpy.py", line 240, in play
    file = write(current_chord=current_chord,
  File "C:\Users\vlign\AppData\Local\Programs\Python\Python310\lib\site-packages\musicpy\musicpy.py", line 849, in write
    current_volume_channel = current_channel if each.channel is None else each.channel
AttributeError: 'int' object has no attribute 'channel'

翻譯和弦判斷算法github wiki的文檔

您好,
我對於和弦判斷算法邏輯這部分特別有興趣,我想要幫忙將這部分算法條目給英翻中。
但我對於github wiki的使用不夠熟,想請問有沒有甚麼特別的內嵌功能可以在原來英文條目添加中文內容,做language switching的時候只顯示特定語言內容;還是一定得開新的頁面添加中文條目?

'str' object has no attribute 'track_number'

musicpy\musicpy.py", line 771, in write
current_chord.track_number, current_chord.start_times, current_chord.instruments_numbers, current_chord.bpm, current_chord.tracks, current_chord.track_names, current_chord.channels, current_chord.pan, current_chord.volume
AttributeError: 'str' object has no attribute 'track_number'

play 时,sh: temp.mid: command not found 报错

作者您好,我按照b站教程,运行如下代码

from musicpy import *

a=note('A',5,duration=3)
b=chd("C5","maj7",duration=1,intervals=1)
play(a)
# print(b)

play这句报错:sh: temp.mid: command not found

请问我该如何处理.

我看了一下play函数的源代码如下

def play(chord1,
         tempo=80,
         track=0,
         channel=0,
         time1=0,
         track_num=1,
         name='temp.mid',
         modes='quick',
         instrument=None,
         save_as_file=True):
    file = write(name_of_midi=name,
                 chord1=chord1,
                 tempo=tempo,
                 track=track,
                 channel=channel,
                 time1=time1,
                 track_num=track_num,
                 mode=modes,
                 instrument=instrument,
                 save_as_file=save_as_file)
    if save_as_file:
        result_file = name
        if sys.platform.startswith('win'):
            os.startfile(result_file)
        elif sys.platform.startswith('linux'):
            import subprocess
            subprocess.Popen(result_file)
        elif sys.platform == 'darwin':
            os.system(result_file)
    else:
        return file

我的电脑是mac,该如何处理这个问题呢。现在在同级目录下有temp.mid这个文件,只是不能播放。需要拖入第三方录音软件听。

Question on using `build` and `interval` notation as pertains to `chord_analysis`

I have a question regarding the interval description:

Starting from a JSON structure, I would like to convert to a musicpy piece and then do a chord analysis as follows :

import json as js
import musicpy as mp
json=js.loads("""[{
			"chd": "Cm7",
			"time": 0.5,
			"arp": 0.125,
			"start": 0,
			"inst": "Acoustic Grand Piano"
		},
		{
			"chd": "Dsus",
			"time": 0.5,
			"arp": 0.125,
			"start": 0.5,
			"inst": "Acoustic Grand Piano"
		},
		{
			"chd": "Caug7",
			"time": 0.5,
			"arp": 0.125,
			"start": 1,
			"inst": "Acoustic Grand Piano"
		},
		{
			"chd": "Dadd2",
			"time": 0.5,
			"arp": 0.125,
			"start": 1.5,
			"inst": "Acoustic Grand Piano"
		},
		{
			"chd": "Cm7",
			"time": 0.5,
			"arp": 0.125,
			"start": 2,
			"inst": "Acoustic Grand Piano"
		},
		{
			"chd": "Dsus",
			"time": 0.5,
			"arp": 0.125,
			"start": 2.5,
			"inst": "Acoustic Grand Piano"
		},
		{
			"chd": "Caug7",
			"time": 0.5,
			"arp": 0.125,
			"start": 3,
			"inst": "Acoustic Grand Piano"
		},
		{
			"chd": "D,G,A,A# / Dadd2",
			"time": 0.5,
			"arp": 0.25,
			"start": 3.5,
			"inst": "Acoustic Grand Piano"
		}
	]""")
def convert_to_mp(chp : list, bpm : float=138, name: str='Progression 0') -> mp.piece:
    """Convert a chord-progression from a dict `chd` to a musicpy object

    Args:
        chp (list): chord progression
        bpm (float): BPM to play the song at.

    Returns:
        mp.piece: musicpy piece from chord progression
    """
    chord = [mp.C(i['chd']) % (i['time'], i['arp']) for i in chp]
    inst = [i['inst'] for i in chp]
    start = [i['start'] for i in chp]
    bpm, chdnotes, _ = mp.piece(chord,inst,bpm,start,['0']*len(chord)).merge()
    return mp.build(mp.track(chdnotes),bpm=bpm,name=name)
    
piece=convert_to_mp(chp=json, bpm=138, name='Progression 0')
mp.chord_analysis(piece.tracks[0])

But this returns ['Cmaj13#11 omit B, G sort as [1, 3, 2, 4, 5]']. I noticed that Track 0 never has any 0-intervals, which I see in other songs.
(output from piece.tracks[0]):

[C4, D#4, G4, A#4, D4, G4, A4, C4, E4, G#4, A#4, D4, E4, F#4, A4, C4, D#4, G4, A#4, G4, C5, D5, G4, B4, D#5, F5, D4, E4, F#4, A4, D5, F#5, A5] with interval [0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.25, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.25, 0.125, 0.125, 0.125, 0.125, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.5]

Could you please explain what I am missing?
Thank you so much!

关于让构建和弦时和弦音的显示更符合乐理的建议

现在使用和弦语法构成和弦似乎默认是以升号表示半音。以三和弦为例,一般认为三和弦是1 3 5的变化,比如

C 大三和弦:1 3 5
Cm 小三和弦 :1 b3 5
Caug 增三和弦:1 3 #5
Cdim 减三和弦 :1 b3 b5

当使用musicpy.C('Cdim')构建和弦,和弦的构成音为[C4, D#4, F#4],能否修改为默认显示[C4, Eb4, Gb4]?这样对于后续进行乐理角度的分析更方便。其他七九十一和弦等等复杂和弦同理。

error: mixer not initialized

environment
google colab

code
same like on your git and pypi

pip install -U musicpy 
from musicpy import *
guitar = (C('CM7', 3, 1/4, 1/8)^2 |
          C('G7sus', 2, 1/4, 1/8)^2 |
          C('A7sus', 2, 1/4, 1/8)^2 |
          C('Em7', 2, 1/4, 1/8)^2 | 
          C('FM7', 2, 1/4, 1/8)^2 |
          C('CM7', 3, 1/4, 1/8)@1 |
          C('AbM7', 2, 1/4, 1/8)^2 |
          C('G7sus', 2, 1/4, 1/8)^2) * 2
play(guitar, bpm=100, instrument=25)

result

error                                     Traceback (most recent call last)
[<ipython-input-9-e2f1c6daee5e>](https://localhost:8080/#) in <cell line: 1>()
----> 1 play(guitar, bpm=100, instrument=25)

[/usr/local/lib/python3.10/dist-packages/musicpy/musicpy.py](https://localhost:8080/#) in play(current_chord, bpm, channel, start_time, name, instrument, i, save_as_file, msg, nomsg, ticks_per_beat, ignore_instrument, ignore_bpm, ignore_track_names, wait, **midi_args)
    291     if save_as_file:
    292         result_file = name
--> 293         pygame.mixer.music.load(result_file)
    294         pygame.mixer.music.play()
    295         if wait:

error: mixer not initialized

best regards

chord类的setvolume方法,当ind参数设为'all'的时候,为什么要对self.notes进行note的类型检查?

如题,在structures.py的1204行里有这样的语句:

available_notes = [i for i in self.notes if type(i) == note]

根据上下文来看,这里的意思是,当ind参数设置为all以后,需要对self.notes里的每个内容进行类型检查,只有那些类型为note的对象才会被修改音量。但是self.notes应该在创建的时候就应该把输入转换成了 note 类型了,如果一定要做类型检查,也应该是在self.notes创建、新增的时候进行检查,而不应该在setvolume这样的方法里做检查。

另外,1199行each = self.notes[current - 1]中的current还没有进行初始化,假如vol类型为int,而ind类型为list,那么进入该分支则会报错。

单个音符滑音

刚刚看到21年加入了区段pitch bend,可以使某点后的音符细微变调,这功能很赞
那么,怎么才能在某一个音符内部实现一个线性或者特定数学函数控制的pitch?比如一个长音,以B4开始,到一半时长开始降调,一直到结束时的A4,或者一个D4,开始时快速向D#4抖动一下再拉回来,配合拨弦音色整出颤音——话说MIDI支持这种指令吗?

Sampler doesn't properly handle 32bit wav files

When playing wav samples of 32bit/44.1khz wav files, the sampler plays them back at the wrong speed which pitches them down. I haven't checked but I would guess that 8/12bit files will playback pitched up.

音符的degree属性可修改,但修改后其他属性并不会跟着改

创建一个音符后,degree属性可修改,但修改后其他属性并不会跟着改,会得到一个错误的音符
例如以下代码:

>>> from musicpy import *
>>> a = note('A', 5)
>>> a.__dict__
{'name': 'A', 'num': 5, 'degree': 81, 'duration': 0.25, 'volume': 100, 'channel': None}
>>> a.degree=80
>>> a.__dict__
{'name': 'A', 'num': 5, 'degree': 80, 'duration': 0.25, 'volume': 100, 'channel': None}
  1. 如果设计时就不希望用户修改degree,那么应该将这个属性设置为只读
  2. 当然如果能够更智能一点,在用户修改degree时自动修改name和num,就更好了

Can't load the module if there is no audio interface

I'd like to use this module to generate loops using a server. But when you try to load the module it tries to initiate the audio interface which fails without an audio interface.

I don't need to playback the audio, I just need to export the loops I generate as WAV file.

The work around is to create a dummy audio interface but it's complicated and I'm having issues keeping the dummy interface running.

pip无法安装

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting musicpy
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c1/d1/46c78c9c1d6968c88436a0e93e7c314e26f1c441692ced349565a39eb98e/musicpy-1.60.tar.gz (100 kB)
     |████████████████████████████████| 100 kB 576 kB/s 
Requirement already satisfied: mido in /usr/local/lib/python3.5/dist-packages (from musicpy) (1.2.9)
Requirement already satisfied: midiutil in /usr/local/lib/python3.5/dist-packages (from musicpy) (1.2.1)
Requirement already satisfied: pygame in /usr/local/lib/python3.5/dist-packages (from musicpy) (2.0.1)
Requirement already satisfied: pillow in /usr/lib/python3/dist-packages (from musicpy) (3.1.2)
Building wheels for collected packages: musicpy
  Building wheel for musicpy (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/setup.py'"'"'; __file__='"'"'/tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-7ke3swbq
       cwd: /tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/
  Complete output (28 lines):
  /usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/musicpy
  copying musicpy/__init__.py -> build/lib/musicpy
  copying musicpy/structures.py -> build/lib/musicpy
  copying musicpy/match.py -> build/lib/musicpy
  copying musicpy/database.py -> build/lib/musicpy
  copying musicpy/musicpy.py -> build/lib/musicpy
  running egg_info
  writing top-level names to musicpy.egg-info/top_level.txt
  writing musicpy.egg-info/PKG-INFO
  writing dependency_links to musicpy.egg-info/dependency_links.txt
  writing requirements to musicpy.egg-info/requires.txt
  reading manifest file 'musicpy.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'musicpy.egg-info/SOURCES.txt'
  creating build/lib/musicpy/__pycache__
  copying musicpy/__pycache__/__init__.cpython-37.pyc -> build/lib/musicpy/__pycache__
  copying musicpy/__pycache__/database.cpython-37.pyc -> build/lib/musicpy/__pycache__
  copying musicpy/__pycache__/match.cpython-37.pyc -> build/lib/musicpy/__pycache__
  copying musicpy/__pycache__/musicpy.cpython-37.pyc -> build/lib/musicpy/__pycache__
  copying musicpy/__pycache__/structures.cpython-37.pyc -> build/lib/musicpy/__pycache__
  error: can't copy 'musicpy/__pycache__': doesn't exist or not a regular file
  ----------------------------------------
  ERROR: Failed building wheel for musicpy
  Running setup.py clean for musicpy
Failed to build musicpy
Installing collected packages: musicpy
    Running setup.py install for musicpy ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/setup.py'"'"'; __file__='"'"'/tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-gamuuxo2/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.5/musicpy
         cwd: /tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/
    Complete output (28 lines):
    /usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/musicpy
    copying musicpy/__init__.py -> build/lib/musicpy
    copying musicpy/structures.py -> build/lib/musicpy
    copying musicpy/match.py -> build/lib/musicpy
    copying musicpy/database.py -> build/lib/musicpy
    copying musicpy/musicpy.py -> build/lib/musicpy
    running egg_info
    writing musicpy.egg-info/PKG-INFO
    writing requirements to musicpy.egg-info/requires.txt
    writing top-level names to musicpy.egg-info/top_level.txt
    writing dependency_links to musicpy.egg-info/dependency_links.txt
    reading manifest file 'musicpy.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'musicpy.egg-info/SOURCES.txt'
    creating build/lib/musicpy/__pycache__
    copying musicpy/__pycache__/__init__.cpython-37.pyc -> build/lib/musicpy/__pycache__
    copying musicpy/__pycache__/database.cpython-37.pyc -> build/lib/musicpy/__pycache__
    copying musicpy/__pycache__/match.cpython-37.pyc -> build/lib/musicpy/__pycache__
    copying musicpy/__pycache__/musicpy.cpython-37.pyc -> build/lib/musicpy/__pycache__
    copying musicpy/__pycache__/structures.cpython-37.pyc -> build/lib/musicpy/__pycache__
    error: can't copy 'musicpy/__pycache__': doesn't exist or not a regular file
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/setup.py'"'"'; __file__='"'"'/tmp/pip-install-i9geki1a/musicpy_7ae0f7c0837b41c5bb9dd7ab1acbc3bd/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-gamuuxo2/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.5/musicpy Check the logs for full command output.

这是报错信息,是不是什么地方bug了?

[feature req] Integration with hookpad ?

Hi , first of all kudos to work done by you . I am not sure if you are aware of hook pad theory ? basically it is sketching notes and chords with tones of options . It helps in understanding theory in a visual way. I am wondering if the sketch pad can be converted directly into a midi file with musicpy ?

An example for one of the songs is here :https://www.hooktheory.com/theorytab/view/the-beatles/here-comes-the-sun where you can edit the chords and notes.

I think it could be super useful to use both musicpy and hooktheory for faster learning. It was just a thought as hook theory has also lots of music resources

Cannot hear any sound from sample code

Hello again,

Similar to Rainbow-Dreamer/sf2_loader#1, I cannot hear any sound when using the sample code found in the README:

from musicpy import *

guitar = (C('CM7', 4, 1/4, 1/8) ^ 2 | C('G7sus', 3, 1/4, 1/8) ^ 2
          | C('A7sus', 3, 1/4, 1/8) ^ 2 | C('Em7', 3, 1/4, 1/8) ^ 2 |
          C('FM7', 3, 1/4, 1/8) ^ 2 | C('CM7', 4, 1/4, 1/8)@1 |
          C('AbM7', 3, 1/4, 1/8) ^ 2 | C('G7sus', 3, 1/4, 1/8) ^ 2)
play((guitar * 2)-octave, 100, instrument=25)

控制播放

当开始播放一段旋律之后,就不能暂停播放,只能等待播放完毕,也不能拖动进度条。


在jupyter notebook中的解决方案:先判断是否为jupyter notebook

def is_jupyter_notebook()->bool:
    try:
        get_ipython().__class__.__name__
        #jupyter notebook
        return True
    except NameError:
        #普通命令行
        return False

如果不是,则仍使用原来的音频api播放

如果是,则使用jupyter的api播放

播放音频:

#音频数据为audiodata,numpy数组
if(is_jupyter_notebook()):
    from IPython.display import Audio
    return Audio(data=audiodata, rate=44100)

效果:
image

I'm curious about why "math.log" applies to denominator of time_signature message

I would like to develop a score analysis program and I would like to get time signature of each bar.
As a result, I find that time_signature is a message, which can be accessed by bar.other_messages, if the message is present. (If my way of accessing it is wrong, thanks for pointing out)

I have a minuet of 3/4.

Logic pro x gives the correct time signature.
image

But in musicpy,

# musicpy.py:948
        current_message = time_signature(
            track=track_ind,
            time=time,
            numerator=message.numerator,
            denominator=int(math.log(message.denominator, 2)),  #this line
            clocks_per_tick=message.clocks_per_click,
            notes_per_quarter=message.notated_32nd_notes_per_beat)

Logarithm is applied to denominator, and if I print(msg.numerator, msg.denominator), I would get 3/2, which is different from expected.
I am curious about the logarithm. It should be intentional, but I don't quite understand. Thanks!

Demos won't work without an explicit sleep

Hi, I tried some of the demos of sf2_loader and musicpy, but without sleeping, all the notes/pieces won't be played and the program exited in advance. After looking into the code and doing some googling, I found that the audio is played underlying by pygame.mixer, which is supposed to play the audio in the background without blocking(which makes sense in game, discussed in this stackoverflow thread). So after adding a sleep(some_seconds), the demos work as expected.

I tried this on Windows and Linux, with pygame [email protected], sleep is essential in both systems. Is there anything else I have to care if I want to try the demo without sleep? Or this is the design then maybe it's better to add a line of code in the tutorial demos?

Oh, almost forgot to say, it's a great project, good job!

实时变换tempo功能 / 音量问题

能不能加入一种对象,可以像note一样插进一段chord里,其长度为0,作用是被处理到时更改后续序列的tempo,如果chord被打包进piece,则对整个piece生效,类似daw上的tempo轨那样

另外有个小问题,为什么musicpy的volume最高能设定到255?midi标准是到127的,做了一个包含大于127的音符的midi在fluidsynth播放缺音,提示超出127,导入musescore也是大面积缺音,但用java写的播放程序调用jvm自带的gervill就可以正常播放;如果把音符全改成127以下,fluidsynth正常播放,但声音很小,和手上一些其他的midi文件相比只有一半左右,这是什么情况?后续会修复吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.