-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharranger.py
executable file
·126 lines (99 loc) · 3.49 KB
/
arranger.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
# encoding: utf=8
"""
arranger.py
Given an audio file provide the means to audition each section and rearrange
the track by sections including deletes and repeats.
By Dave and Nick, 2013.
Example operation:
"Track includes sections 1..12."
> p 4 6 9
(play sections 4 6 9)
> a 2 2 5 3 4 6 7 8 9 8 8 2 12
(arrange sections; rearranged track plays)
> s output_filename
(new mp3 saved to output_filename)
"""
import subprocess
import time
import webbrowser
import soundcloud
from engine import Engine
USAGE = """
Usage:
python arranger.py input_filename
"""
HELP = """ a <sections> - arrange sections (e.g. a 2 2 4 5 10)
p [<sections>] - play sections (e.g. p 4 5 6) or current arrangement
k - kill current playback
s <filename> - save current arrangement (option to upload to SoundCloud)
h - help
q - quit"""
def main(input_filename=None):
if input_filename:
engine = Engine(input_filename)
sections = engine.get_sections()
print("track includes sections 1..%d" % len(sections))
else:
engine = None
client = soundcloud.Client(access_token = "1-58194-65838022-e30bc60d1afac57")
while True:
cmd = raw_input("arranger > ")
if len(cmd) == 0:
continue
if cmd[0].lower() == "p":
if engine:
engine.play([int(x) - 1 for x in cmd.split()[1:]])
else:
print "load a track with 'l <filename>'"
elif cmd[0].lower() == "a":
if engine:
engine.arrange([int(x) - 1 for x in cmd.split()[1:]])
else:
print "load a track with 'l <filename>'"
elif cmd[0].lower() == "s":
if engine:
name = cmd[2:]
if len(name) < 1:
print "empty name"
continue
engine.save(name)
if not '.' in name:
name = name + '.mp3'
yesNo = raw_input("Upload track to SoundCloud? (y/n) > ")
if yesNo.lower().startswith("y"):
title = raw_input("Name your sound > ")
genre = raw_input("What genre is your sound? > ")
tags = raw_input("Add comma-separated tags > ")
track_dict = {'title': title, 'asset_data': open(name, 'rb'), 'genre': genre, 'tag_list': tags}
track_dict.update({'sharing': 'public'})
track = client.post('/tracks', track = track_dict)
while track.state != "finished":
time.sleep(1)
track = client.get("/tracks/" + str(track.id))
webbrowser.open(track.permalink_url)
else:
continue
else:
print "load a track with 'l <filename>'"
elif cmd[0].lower() == "l":
if engine:
engine.kill()
new_filename = cmd[1:].strip()
engine = Engine(new_filename)
print("track includes sections 1..%d" % len(engine.get_sections()))
elif cmd[0].lower() == "h":
print HELP
elif cmd[0].lower() == "k":
if engine:
engine.kill()
elif cmd[0].lower() == "q":
if engine:
engine.kill()
break
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
main(sys.argv[1])
else:
main()