def compose(self): self.song = Song(self.tracks, self.length) for i in range(0, self.tracks): self.song.add_track( Track(start=i * (self.length // self.tracks), instrument=random.choice(self.instrument) - 1, length=self.length, samples=self.samples, bass=False, sample_lengths=self.sample_length, step=self.step, intense=self.intense, flow=self.flow_ratio, tempo=self.tempo, seed_ratio=self.seed_ratio, seed_range=self.seed_range, down_willing_ratio=self.down_willing_ratio, key=self.key)) if self.bass_sample: self.song.add_track( Track(0, 35, self.length, self.tempo, 1, True, 15, intense=90, key=self.key)) self.song.save_song(self.output)
def test_every_field_not_unknown_on_vaild_contruction(self): song = Song(**self.song_dict) self.assertNotEqual('Unknown Artist', song.artist) self.assertNotEqual('Unknown Title', song.title) self.assertNotEqual('Unknown Album', song.artist) self.assertNotEqual('Unknown ID', song.storeId) self.assertNotEqual('Unknown ID', song.artistId) self.assertNotEqual('Unknown ID', song.albumId) self.assertNotEqual('Unknown Duration', song.duration) self.assertNotEqual('Unknown Album Art', song.albumArt)
def test_every_field_unknown_on_bad_construction(self): song = Song() self.assertEqual('Unknown Artist', song.artist) self.assertEqual('Unknown Title', song.title) self.assertEqual('Unknown Album', song.album) self.assertEqual('Unknown ID', song.storeId) self.assertEqual('Unknown ID', song.artistId) self.assertEqual('Unknown ID', song.albumId) self.assertEqual('Unknown Duration', song.duration) self.assertEqual('Unknown Album Art', song.albumArt)
import sys from scripts.song import Song if __name__ == "__main__": if len(sys.argv) != 3: raise RuntimeError("You have to specify file name (starting with is enough) and num of transposition") # for song in [Song.load_song("Stairway")]: # for song in Song.load_songs(): # song.transpose(1) # for i in range(12): # song.transpose(1) Song.transpose(Song.load_song(sys.argv[1]), int(sys.argv[2]))
def add_song_next(self, **song_details): song = Song(**song_details) self._song_queue.insert(0, song)
def add_song(self, **song_details): song = Song(**song_details) self._song_queue.append(song)
def add_station(self, **song_details): song = Song(**song_details) tracks = self._jukebox.create_station(song.storeId) for track in tracks: self.add_song(**track)
from scripts.song import Song if __name__ == "__main__": songs = Song.load_songs() widest = map( lambda song: f"{song.title} {song.text.width} {song.text.height}", sorted(songs, key=lambda song: song.text.width, reverse=True)[:10]) print(f"Widest songs: {list(widest)}") highest = map( lambda song: f"{song.title} {song.text.width} {song.text.height}", sorted(songs, key=lambda song: song.text.height, reverse=True)[:10]) print(f"Highest songs: {list(highest)}")
class Composer: """Class responsible for composing music""" def __init__( self, length, # length of song in beat instruments_list=[33, 43, 56], tempo=550, # tempo of song in beat per minute output="my_file.mid", # path to output file samples=3, # amount of samples to duplicate in track bass_sample=False, # flag saying if bass line is required sample_length=15, # length of sample to generate step=1, # average difference of pitch note change tracks=1, intense=100, # intense of sample in time flow_ratio=75, # frequency of note pitch change ratio <-(0,100) seed_ratio=70, # frequency of seeding in harmonical samples<-(0,100) seed_range=8, # range of seeding in harmonical samples <-(0,100) down_willing_ratio=50, # ratio of getting low witch pitch in harmonical samples jump=2, # avarega pitch diference in bass line rude=50, # ratio of ignoring parameters, and gerating random in bassline key="c", # key in which music is generated losing=0 # ratio of ignoring notes in generating midi ): """Initializes a composer""" self.key = key self.rude = rude self.jump = jump self.tracks = tracks self.down_willing_ratio = down_willing_ratio self.seed_range = seed_range self.seed_ratio = seed_ratio self.flow_ratio = flow_ratio self.step = step self.intense = intense self.sample_length = sample_length self.bass_sample = bass_sample self.samples = samples self.output = output self.losing = losing self.tempo = tempo self.length = length self.instrument = instruments_list def compose(self): self.song = Song(self.tracks, self.length) for i in range(0, self.tracks): self.song.add_track( Track(start=i * (self.length // self.tracks), instrument=random.choice(self.instrument) - 1, length=self.length, samples=self.samples, bass=False, sample_lengths=self.sample_length, step=self.step, intense=self.intense, flow=self.flow_ratio, tempo=self.tempo, seed_ratio=self.seed_ratio, seed_range=self.seed_range, down_willing_ratio=self.down_willing_ratio, key=self.key)) if self.bass_sample: self.song.add_track( Track(0, 35, self.length, self.tempo, 1, True, 15, intense=90, key=self.key)) self.song.save_song(self.output)
from scripts.song import Song if __name__ == "__main__": Song.load_songs()