-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscamp_new.py
110 lines (97 loc) · 2.66 KB
/
scamp_new.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
from scamp import *
from mingus.containers import Note
# Initialize a new SCAMP session
session = Session()
session.default_soundfont = './GeneralUser/my.sf2'
# Define chords
# Define a dictionary with chord names and their corresponding notes
chords = {
"C": ["C-4", "E-4", "G-4"],
"G": ["G-3", "B-3", "D-4"],
"Am": ["A-3", "C-4", "E-4"],
"Em": ["E-3", "G-3", "B-3"],
"D": ["D-4", "F#-4", "A-4"],
"A": ["A-4", "C#-4", "E-4"],
}
# Define chord progressions for each instrument for each section of the song
instrument_progressions = {
"drums": {
"verse": {
"C": 1,
"G": 1.5,
"Am": 0.5,
"Em": 1,
},
"chorus": {
"C": 1,
"G": 1.5,
"Am": 0.5,
"Em": 1,
},
},
"piano": {
"verse": {
"C": 1,
"G": 1.5,
"Am": 0.5,
"Em": 1,
},
"chorus": {
"C": 1,
"G": 1.5,
"Am": 0.5,
"Em": 1,
},
},
"violin": {
"verse": {
"C": 1,
"G": 1.5,
"Am": 0.5,
"Em": 1,
},
"chorus": {
"C": 1,
"G": 1.5,
"Am": 0.5,
"Em": 1,
},
},
"electric_guitar": {
"verse": {
"Em": 1,
"G": 1.5,
"D": 0.5,
"A": 1,
},
"chorus": {
"C": 1,
"G": 1.5,
"D": 0.5,
"C": 1,
"G": 1,
"Em": 1,
},
},
}
def playPart(instrument_name, section_name, transposition = 0):
instrument = session.new_part(instrument_name)
# current_clock().tempo = int
for chord_name, dur in instrument_progressions[instrument_name][section_name].items():
print(f"Playing chord {chord_name} of {section_name} on {instrument_name} for {dur}")
chord(chord_name, dur, instrument, 0.6, transposition)
wait(dur)
def chord(chord_name, duration, instrument, volume = 0.6, transposition = 0):
chord_pitches = getChordPitches(chord_name)
instrument.play_chord(chord_pitches, volume, duration, blocking=False)
def getChordPitches(chord_name):
chord_notes = [str(note) for note in chords[chord_name]]
chord_pitches = []
for note in chord_notes:
chord_pitches.append(int(Note(note)))
return chord_pitches
# For each instrument and their progressions, create an instrument part and play the chords
# session.fork(playPart, args=("piano", "verse"));
session.fork(playPart, args=("electric_guitar", "verse"));
session.wait_for_children_to_finish();
exit(0);