aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/actions/volume.py
blob: e02cdfabcb66f14dd93d5571b825ecd06378f22c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def run(action, music=None, value=100, fade=0, delta=False, **kwargs):
    if music is not None:
        music.set_volume(value, delta=delta, fade=fade)
    else:
        action.mapping.set_master_volume(value, delta=delta, fade=fade)

def description(action, music=None,
        value=100, delta=False, fade=0, **kwargs):
    formats = []
    message = ""
    if delta:
        if music is not None:
            message += "{:+d}% to volume of « {} »"
            formats.append(value)
            formats.append(music.name)
        else:
            message += "{:+d}% to volume"
            formats.append(value)
    else:
        if music is not None:
            message += "setting volume of « {} » to {}%"
            formats.append(music.name)
            formats.append(value)
        else:
            message += "setting volume to {}%"
            formats.append(value)

    if fade > 0:
        message += " with {}s fade"
        formats.append(fade)

    return _(message).format(*formats)