aboutsummaryrefslogblamecommitdiff
path: root/music_sampler/actions/play.py
blob: fdba95b5b9477617e85dcac8ab6ff67962ab6f8b (plain) (tree)











































                                                                
def run(action, music=None, fade_in=0, start_at=0,
        restart_if_running=False, volume=100,
        loop=0, **kwargs):
    for music in action.music_list(music):
        if restart_if_running:
            if music.is_in_use():
                music.stop()
            music.play(
                    volume=volume,
                    fade_in=fade_in,
                    start_at=start_at,
                    loop=loop)
        elif not music.is_in_use():
            music.play(
                    volume=volume,
                    fade_in=fade_in,
                    start_at=start_at,
                    loop=loop)

def description(action, music=None, fade_in=0, start_at=0,
        restart_if_running=False, volume=100, loop=0, **kwargs):
    message = "starting "
    if music is not None:
        message += "« {} »".format(music.name)
    else:
        message += "all musics"

    if start_at != 0:
        message += " at {}s".format(start_at)

    if fade_in != 0:
        message += " with {}s fade_in".format(fade_in)

    message += " at volume {}%".format(volume)

    if loop > 0:
        message += " {} times".format(loop + 1)
    elif loop < 0:
        message += " in loop"

    if restart_if_running:
        message += " (restarting if already running)"

    return message