def define_sound_and_music(): """Define sound and music.""" # Sound effects pyxel.sound(0).set(note="c3e3g3c4c4", tone="s", volume="4", effect=("n" * 4 + "f"), speed=7) pyxel.sound(1).set( note="f3 b2 f2 b1 f1 f1 f1 f1", tone="p", volume=("4" * 4 + "4321"), effect=("n" * 7 + "f"), speed=9, ) melody1 = ("c3 c3 c3 d3 e3 r e3 r" + ("r" * 8) + "e3 e3 e3 f3 d3 r c3 r" + ("r" * 8) + "c3 c3 c3 d3 e3 r e3 r" + ("r" * 8) + "b2 b2 b2 f3 d3 r c3 r" + ("r" * 8)) melody2 = ("rrrr e3e3e3e3 d3d3c3c3 b2b2c3c3" + "a2a2a2a2 c3c3c3c3 d3d3d3d3 e3e3e3e3" + "rrrr e3e3e3e3 d3d3c3c3 b2b2c3c3" + "a2a2a2a2 g2g2g2g2 c3c3c3c3 g2g2a2a2" + "rrrr e3e3e3e3 d3d3c3c3 b2b2c3c3" + "a2a2a2a2 c3c3c3c3 d3d3d3d3 e3e3e3e3" + "f3f3f3a3 a3a3a3a3 g3g3g3b3 b3b3b3b3" + "b3b3b3b4 rrrr e3d3c3g3 a2g2e2d2") # Music pyxel.sound(2).set( note=melody1 * 2 + melody2 * 2, tone="s", volume=("3"), effect=("nnnsffff"), speed=20, ) harmony1 = ("a1 a1 a1 b1 f1 f1 c2 c2" "c2 c2 c2 c2 g1 g1 b1 b1" * 3 + "f1 f1 f1 f1 f1 f1 f1 f1 g1 g1 g1 g1 g1 g1 g1 g1") harmony2 = (("f1" * 8 + "g1" * 8 + "a1" * 8 + ("c2" * 7 + "d2")) * 3 + "f1" * 16 + "g1" * 16) pyxel.sound(3).set(note=harmony1 * 2 + harmony2 * 2, tone="t", volume="5", effect="f", speed=20) pyxel.sound(4).set( note=("f0 r a4 r f0 f0 a4 r" "f0 r a4 r f0 f0 a4 f0"), tone="n", volume="6622 6622 6622 6426", effect="f", speed=20, ) pyxel.music(0).set([], [2], [3], [4])
def __set_music0(self): self.__set_sounds() # ch1 = [pyxel.sound(0)] # ch2 = [pyxel.sound(1)] ch1 = [self.sounds[0]] ch2 = [self.sounds[1]] ch3 = [] ch4 = [] self.music0 = 0 pyxel.music(self.music0).set(ch1, ch2, ch3, ch4)
def _play(self, is_partial): self.is_playing_var = True self._music_picker.is_enabled_var = False self._play_button.is_enabled_var = False self._stop_button.is_enabled_var = True self._loop_button.is_enabled_var = False tick = 0 if is_partial: for i in range(self.field_cursor.x): music = pyxel.music(self.music_no_var) sound = pyxel.sound(music.snds_list[self.field_cursor.y][i]) tick += len(sound.notes) * sound.speed pyxel.playm(self.music_no_var, tick=tick, loop=self.should_loop_var)
def get_data(self, value): music = pyxel.music(self._music_picker.value) if value == 0: data = music.ch0 elif value == 1: data = music.ch1 elif value == 2: data = music.ch2 elif value == 3: data = music.ch3 return data
def margePyxelFiles(img_file_path, music_file_path, save_to): """img_file + music_file -> marged_file assume 'pixel-artist' and 'music-maker' work together this comine img_bank and music_bank (no check data exist or not)""" # FIXME: the game-window never ended Corretly # check all file extension is .pyxel try: assert os.path.basename(img_file_path).split(".")[-1] == "pyxel" assert os.path.basename(music_file_path).split(".")[-1] == "pyxel" assert os.path.basename(save_to).split(".")[-1] == "pyxel" except AssertionError: print("AssertionError: Check file paths (extension must be .pyxel)") # === Constants from constants.py=== RENDERER_IMAGE_COUNT=4 AUDIO_SOUND_COUNT = 65 AUDIO_MUSIC_COUNT = 8 pyxel.init(1,1) # need to pyxel.load data = {"version": pyxel.VERSION} # load img data from 'img_file_path' pyxel.load(img_file_path) image_list = [ pyxel.image(i).data.dumps() for i in range(RENDERER_IMAGE_COUNT - 1) ] data["image"] = image_list # tilemap_list = [ # (pyxel.tilemap(i).data.dumps(), pyxel.tilemap(i).refimg) # for i in range(RENDERER_TILEMAP_COUNT) # ] # data["tilemap"] = tilemap_list # load music data from 'music_file_path' pyxel.load(music_file_path) sound_list = [pyxel.sound(i) for i in range(AUDIO_SOUND_COUNT - 1)] data["sound"] = sound_list music_list = [pyxel.music(i) for i in range(AUDIO_MUSIC_COUNT - 1)] data["music"] = music_list pickled_data = pickle.dumps(data) with gzip.open(save_to, mode="wb") as fp: fp.write(pickled_data) print("Corretly Saved Data. : {}".format(save_to)) pyxel.quit()
def update(self): if not self.isPlay: for i in range(len(self.tune)): pyxel.sound(i).set_note(self.tune[i]) pyxel.sound(i).speed = 10 pyxel.sound(1).set_tone('S') pyxel.sound(1).set_effect('F') pyxel.sound(2).set_tone('N') pyxel.sound(2).set_effect('F') if len(self.tune) > 0: pyxel.music(0).set_ch0([0]) if len(self.tune) > 1: pyxel.music(0).set_ch1([1]) if len(self.tune) > 2: pyxel.music(0).set_ch2([2]) if len(self.tune) > 3: pyxel.music(0).set_ch3([3]) pyxel.playm(0, loop=True) self.isPlay = True
def define_sound_and_music(): """Define sound and music.""" # Sound effects pyxel.sound(0).set("a3a2c1a1", "p", "7", "s", 5) pyxel.sound(1).set("a3a2c2c2", "n", "7742", "s", 10) pyxel.sound(2).set("c1c1c1a3a3a3c1c1c1", "p", "7", "s", 5) # Music pyxel.sound(3).set( "r a1b1c2 b1b1c2d2 g2g2g2g2 c2c2d2e2" "f2f2f2e2 f2e2d2c2 d2d2d2d2 g2g2r r ", "s", "6", "nnff vfff vvvv vfff svff vfff vvvv svnn", 25, ) pyxel.sound(4).set( "c1g1c1g1 c1g1c1g1 b0g1b0g1 b0g1b0g1" "a0e1a0e1 a0e1a0e1 g0d1g0d1 g0d1g0d1", "t", "7", "n", 25, ) pyxel.sound(4).set( "f0c1f0c1 g0d1g0d1 c1g1c1g1 a0e1a0e1" "f0c1f0c1 f0c1f0c1 g0d1g0d1 g0d1g0d1", "t", "7", "n", 25, ) pyxel.music(0).set([3], [3], [3], [3]) pyxel.music(1).set([4], [4], [4], [4]) pyxel.music(2).set([5], [5], [5], [5])
def get_field(self, index): if index >= pyxel.NUM_CHANNELS: return music = pyxel.music(self.music_no_var) return music.snds_list[index]
def init_sounds(): """ Soundの初期登録をする """ # 左側チームの得点音 pyxel.sound(Sound.LEFT_POINT.value).set(note="c3e3g3c4c4", tone="s", volume="4", effect=("n" * 4 + "f"), speed=5) # 右側チームの得点音 pyxel.sound(Sound.RIGHT_POINT.value).set( note="f3b2f2b1", tone="p", volume="4", effect=("n" * 7 + "f"), speed=5, ) # BGM # とりあえずサンプルを拝借 melody = ("rrrr e3e3e3e3 d3d3c3c3 b2b2c3c3" + "a2a2a2a2 c3c3c3c3 d3d3d3d3 e3e3e3e3" + "rrrr e3e3e3e3 d3d3c3c3 b2b2c3c3" + "a2a2a2a2 g2g2g2g2 c3c3c3c3 g2g2a2a2" + "rrrr e3e3e3e3 d3d3c3c3 b2b2c3c3" + "a2a2a2a2 c3c3c3c3 d3d3d3d3 e3e3e3e3" + "f3f3f3a3 a3a3a3a3 g3g3g3b3 b3b3b3b3" + "b3b3b3b4 rrrr e3d3c3g3 a2g2e2d2") harmony1 = ("a1 a1 a1 b1 f1 f1 c2 c2" "c2 c2 c2 c2 g1 g1 b1 b1" * 3 + "f1 f1 f1 f1 f1 f1 f1 f1 g1 g1 g1 g1 g1 g1 g1 g1") harmony2 = (("f1" * 8 + "g1" * 8 + "a1" * 8 + ("c2" * 7 + "d2")) * 3 + "f1" * 16 + "g1" * 16) pyxel.sound(Sound.BGM_2.value).set(note=harmony1 * 2 + harmony2 * 2, tone="t", volume="5", effect="f", speed=20) pyxel.sound(Sound.BGM_3.value).set( note=("f0 r a4 r f0 f0 a4 r" "f0 r a4 r f0 f0 a4 f0"), tone="n", volume="6622 6622 6622 6426", effect="f", speed=20, ) pyxel.sound(Sound.BGM_1.value).set( note=melody, tone="s", volume=("3"), effect=("nnnsffff"), speed=20, ) ch0 = [] ch1 = [ Sound.BGM_1.value, ] ch2 = [ Sound.BGM_2.value, ] ch3 = [ Sound.BGM_3.value, ] pyxel.music(Music.MAIN_BGM.value).set(ch0, ch1, ch2, ch3)
def prep_music(): n = "c1,c#1,d1,d#1,e1,f1,f#1,g1,g#1,a1,a#1,b1," notes = n + n.replace("1", "2") + n.replace("1", "3") + n.replace("1", "4") notes = notes.split(",") blues = [0, 3, 5, 6, 7, 10] maj = [0, 2, 4, 5, 7, 9, 11] min = [0, 2, 3, 5, 7, 8, 10] mixy = [0, 4, 5, 7, 11] pent = [0, 4, 7, 9] spanish = [0, 1, 4, 5, 7, 8, 11] all_scales = [] scales = [blues, maj, min, mixy, pent] for intervals in scales: all_scales.append(intervals + [i + 12 for i in intervals] + [i + 24 for i in intervals] + [i + 36 for i in intervals]) for i, scale in enumerate(all_scales): print(scale) print(notes) all_scales[i] = [notes[j] for j in scale] print(all_scales) scale = choice(all_scales) riddims = [["{0} r r r {2} r r r"] * 2, ["{0}{1} r r {0}{0} r r"], ["{0} r {1} r {0}{0}{0}{0}"], ["{0}{0}{1}{1}{0}{2}{0}{2}"], ["{0} r {0} r {1} r r r"], ["{0} r {0} r {1} r r r"], ["{0} r {1} r {2} r {0} r"] * 2] if probability(50): beats = ["c1rrrb4rrr" * 2, "c1rrrb4rrrc1rrc1b4rrr" "c1rrrb4rrrc1rrrb4rrc1", "c1rrrb4rrrc1rrc1b4rc1r", "c1rb4rb4rb4r" * 2] else: beats = ["c1r r r r r r r a4r r r r r r r ", "c1r r r r r r r a4r g4r f4r r r", "c1 r r rc1r r r a4r r r r r r r", "c1r r r c1r c1r a4r r r r r r r", "c1r r r r r c1r a4r c1r r r r r", "c1r r r r r r r a4r c1a4r a4r r"] melodies = [] for i in range(8): melody = "" if probability(50): root = randint(0, len(scale)) else: root = len(scale) // 2 note = root j = 0 notes = 0 for j in range(16): if j > 0 and probability(i * 5): melody += "r" else: count = 1 if probability(25) else 2 for i in range(count): change = choice([-1, 0, 0, 1]) if probability(75): change *= 2 if probability(75): change *= 1.5 if probability(25): note = root note += int(change) notes += 1 try: melody += scale[note] except IndexError: note = root melody += scale[note] melodies.append(melody) final_melody = "" bass = "" drums = "" print(melodies) bars = 256 while bars > 0: reps = choice([4, 2, 1]) this_mel = choice(melodies) if probability(50): upbeat = "" if probability(75): rest = "r" if probability(50): if probability(50): upbeat = "r" rest = "rr" else: rest = "rrr" this_mel = upbeat+"".join([note + rest for note in split_mel(this_mel)][:16]) cadence = choice([[0, 4] * 4, [0, 3, 4]* 3]) print(scale) print(cadence) bass_notes = [scale[i] for i in cadence] print(bass_notes) bass += choice(riddims)[0].format(*bass_notes) bars -= (reps * 8) drums += choice(beats) if probability(75): final_melody += this_mel * reps else: final_melody += ("r" * 16) * reps print(final_melody) speed = randint(10, 20) # Music # List of effects(0:None / 1:Slide / 2:Vibrato / 3:FadeOut) pyxel.sound(2).set( note=final_melody, tone="t", volume=("1"), effect=(""), speed=speed, ) pyxel.sound(1).set( note=bass, tone="P", volume=("3"), effect=(""), speed=speed, ) pyxel.sound(3).set( note=drums, tone="N", volume=("3"), effect=(""), speed=speed, ) # pyxel.sound(3).set( # note=harmony1 * 2 + harmony2 * 2, tone="t", volume="5", effect="f", speed=20 # ) # pyxel.sound(4).set( # note=("f0 r a4 r f0 f0 a4 r" "f0 r a4 r f0 f0 a4 f0"), # tone="n", # volume="6622 6622 6622 6426", # effect="f", # speed=20, # ) pyxel.music(0).set([], [1], [2], [3])
def init_sounds(): """ Soundの初期登録をする """ # 左側チームの得点音 pyxel.sound(Sound.LEFT_POINT.value).set(note="c3e3g3c4c4", tone="s", volume="4", effect=("n" * 4 + "f"), speed=5) # 右側チームの得点音 pyxel.sound(Sound.RIGHT_POINT.value).set( note="f3b2f2b1", tone="p", volume="4", effect=("n" * 7 + "f"), speed=5, ) # BGM katyusha_melody1 = ('d3d3d3d3 d3d3e3e3 f3f3f3f3 f3f3d3d3' + 'f3f3f3f3 e3e3d3d3 e3e3e3e3 a2a2a2a2' + 'e3e3e3e3 e3e3f3f3 g3g3g3g3 g3g3e3e3' + 'g3g3g3g3 f3f3e3e3 d3d3d3d3 d3d3d3d3') katyusha_melody2 = ('a3a3a3a3 d4d4d4d4 c4c4c4c4 d4d4c4c4' + 'b-3b-3b-3b-3 a3a3g3g3 a3a3a3a3 d3d3d3d3' + 'rrb-3b-3 b-3b-3g3g3 a3a3a3a3 a3a3f3f3' + 'g3g3g3g3 f3f3e3e3 d3d3d3d3 d3d3d3r') katsusha_base_1 = ('d2d2a2a2 d2d2a2a2 d2d2a2a2 d2d2a2a2' + 'd2d2a2a2 d2d2a2a2 a1a1c#2c#2 a1a1e2e2' + 'a1a1c#2c#2 a1a1e2e2 a1a1c#2c#2 a1a1e2e2' + 'a1a1e2e2 a1a1e2e2 d2d2a2a2 d2d2a2a2') katsusha_base_2 = ('b-1b-1f2f2 b-1b-1f2f2 a1a1c#2c#2 a1a1e2e2' + 'g1g1d2d2 g1g1b-1b-1 d2d2a2a2 d2d2a2a2' + 'g1g1d2d2 g1g1b-1b-1 d2d2a2a2 d2d2a2a2' + 'a1a1e2e2 a1a1e2e2 d2d2a2a2 d2d2a2a2') katsusha = katyusha_melody1 + katyusha_melody2 * 2 katsusha_base = katsusha_base_1 + katsusha_base_2 * 2 pyxel.sound(Sound.BGM_1.value).set( note=katsusha, tone="s", volume=("3"), effect=("n"), speed=12, ) pyxel.sound(Sound.BGM_2.value).set( note=katsusha_base, tone="t", volume=("2"), effect=("n"), speed=12, ) ch0 = [] ch1 = [ Sound.BGM_1.value, ] ch2 = [ Sound.BGM_2.value, ] ch3 = [ Sound.BGM_3.value, ] pyxel.music(Music.MAIN_BGM.value).set(ch0, ch1, ch2, ch3)