def run(self, ticks): SceneClient.run(self, ticks) if not self.wizardStarted: self.wizardStarted = True if not self.songName: while True: self.libraryName, self.songName = \ Dialogs.chooseSong(self.engine, \ selectedLibrary = Config.get("game", "selected_library"), selectedSong = Config.get("game", "selected_song")) if not self.songName: self.session.world.finishGame() return Config.set("game", "selected_library", self.libraryName) Config.set("game", "selected_song", self.songName) info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) d = Dialogs.chooseItem(self.engine, info.difficulties, _("Choose a difficulty:"), selected = self.player.difficulty) if d: self.player.difficulty = d break else: info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) # Make sure the difficulty we chose is available if not self.player.difficulty in info.difficulties: self.player.difficulty = info.difficulties[0] self.session.world.deleteScene(self) self.session.world.createScene("GuitarScene", libraryName = self.libraryName, songName = self.songName)
def clickAddQue(self, listbox1, listbox2): queueSongTitle = listbox1.get(listbox1.curselection()) if queueSongTitle == None: #upon startup, the default song is the first song queueSong = Song.Song() else: #recreate song object from selected song title in listbox queueSongPath = self.mp3_object.getPath() + "/" + queueSongTitle queueSong = Song.Song(queueSongPath) self.mp3_object.addToQueue(queueSong) listbox2.insert(listbox2.size(), queueSong.getTitle())
def createClient(self, libraryName, songName, players = 1): #players = None Log.debug("GameResultsSceneClient class init...") self.libraryName = libraryName self.songName = songName self.stars = [0 for i in players] self.accuracy = [0 for i in players] self.counter = 0 self.showHighscores = False self.highscoreIndex = [-1 for i in players] self.taunt = None self.uploadingScores = False self.uploadResult = None self.nextScene = None self.offset = None self.pauseScroll = None self.scorePart = None self.scoreDifficulty = None self.playerList = players self.spinnyDisabled = True#NO SPINNY!!! #myfingershurt: reordering so default is Change Song. items = [ (_("Continue"), self.changeSong), (_("Replay"), self.replay), (_("Quit"), self.quit), ] self.menu = Menu(self.engine, items, onCancel = self.quit, pos = (.2, .5)) self.engine.resource.load(self, "song", lambda: Song.loadSong(self.engine, songName, library = self.libraryName, notesOnly = True, part = [player.part for player in self.playerList]), onLoad = self.songLoaded) #Get theme themename = self.engine.data.themeLabel #now theme determination logic is only in data.py: self.theme = self.engine.data.theme self.starScoring = self.engine.config.get("game", "star_scoring")#MFH self.Congratphrase = self.engine.config.get("game", "congrats")#blazingamer self.resultCheerLoop = self.engine.config.get("game", "result_cheer_loop")#MFH self.cheerLoopDelay = self.engine.config.get("game", "cheer_loop_delay")#MFH self.cheerLoopCounter = self.cheerLoopDelay #MFH - starts out ready to cheer self.engine.loadImgDrawing(self, "background", os.path.join("themes",themename,"gameresults.png")) phrase = random.choice(Theme.resultsPhrase.split("_")) if phrase == "None": i = random.randint(0,5) if i == 0: phrase = _("Relax, it was an excellent show.") elif i == 1: phrase = _("Truly Amazing!") elif i == 2: phrase = _("Thanks for playing!") elif i == 3: phrase = _("One more song can't hurt, can it?") elif i == 4: phrase = _("What an amazing performance!") else: phrase = _("That's how it's done!") Dialogs.showLoadingScreen(self.engine, lambda: self.song, text = phrase)
def importPlaylist(self): path, dir, mp3files = next(os.walk(self.path)) self.files = mp3files self.path = path #create song objects for each mp3 file found. Store in MusicLibrary for mp3 in self.files: mp3path = self.path + "/" + mp3 newSong = Song.Song(mp3path) self.musicDictionary[newSong] = newSong.getPath() # #order songs in alphabetical order in musiclibrary # h = 0 # while h < len(self.musicLibrary): # i = 0 # while i < len(self.musicLibrary) - 1: # firstSong = self.musicLibrary[i] # secSong = self.musicLibrary[i + 1] # #compare titles # j = 0 # while j < len(secSong.getTitle()): #always comparing against the shortest song name # if secSong.getTitle()[j] < firstSong.getTitle()[j]: #if the second song comes first # self.musicLibrary[i] = secSong # self.musicLibrary[i + 1] = firstSong # i += 1 # j = len(secSong.getTitle()) #break out of for loop # elif secSong.getTitle()[j] > firstSong.getTitle()[j]: #if first song comes first # i += 1 # j = len(secSong.getTitle()) # elif secSong.getTitle()[j] == firstSong.getTitle()[j]: # j += 1 # h += 1 #set first song as currentSong by default self.currentSong = list(self.musicDictionary.keys())[0]
def snippet_analyzer(snippet): ''' This function analyzes the snippet signal and find the match in the song library Keyword Argument: snippet_signal -- A dictionary with fields including signal, name, sampling_rate, and audio_source ''' snippet_signal = snippet['audio_signal'] snippet_name = snippet['audio_name'] sampling_rate = snippet['sampling_rate'] snippet_address = snippet['audio_source'] # Construct a Song Object called snippet_song snippet_song = Song.Song(snippet_signal, title_info=snippet_name, address_info=snippet_address, sampling_rate_info=sampling_rate) # Use the signature of the snippet to find match in the # song library matched_song, matched_time, params_cp, T, acy_level = signature_match( snippet_song.signature) # Return the matching information print(f"""The snippet matches with the song with title {matched_song[1]}, created by {matched_song[2]}""") print(f"""The recording has a sampling rate of {int(matched_song[3])} and lasts {round(float(matched_song[4]), 1)} seconds""") print(f"""The snippet matches with {matched_song[1]} at as early as {float(min(matched_time))} seconds""") K = params_cp.k L = params_cp.l lsh_family = str(params_cp.lsh_family) print(f"""Use {K} {lsh_family} function and {L} hash tables, {T} probes for approximate NN search.""")
def createClient(self, libraryName, songName, players = None): self.libraryName = libraryName self.songName = songName self.stars = [0 for i in players] self.accuracy = [0 for i in players] self.counter = 0 self.showHighscores = False self.highscoreIndex = [None for i in players] self.taunt = None self.uploadingScores = False self.nextScene = None self.offset = None self.pauseScroll = None self.scorePart = None self.scoreDifficulty = None self.playerList = players self.spinnyDisabled = self.engine.config.get("game", "disable_spinny") items = [ (_("Replay"), self.replay), (_("Change Song"), self.changeSong), (_("Quit to Main Menu"), self.quit), ] self.menu = Menu(self.engine, items, onCancel = self.quit, pos = (.2, .5)) self.engine.resource.load(self, "song", lambda: Song.loadSong(self.engine, songName, library = self.libraryName, notesOnly = True, part = [player.part for player in self.playerList]), onLoad = self.songLoaded) self.engine.loadSvgDrawing(self, "background", "gameresults.svg") phrase = random.choice(Theme.resultsPhrase.split(",")) if phrase == "None": phrase = _("Chilling...") Dialogs.showLoadingScreen(self.engine, lambda: self.song, text = phrase)
def createClient(self, libraryName, songName): self.libraryName = libraryName self.songName = songName self.stars = 0 self.accuracy = 0 self.counter = 0 self.showHighscores = False self.highscoreIndex = None self.taunt = None self.uploadingScores = False self.nextScene = None items = [ (_("Replay"), self.replay), (_("Change Song"), self.changeSong), (_("Quit to Main Menu"), self.quit), ] self.menu = Menu(self.engine, items, onCancel=self.quit, pos=(.2, .5)) self.engine.resource.load( self, "song", lambda: Song.loadSong(self.engine, songName, library=self.libraryName, notesOnly=True), onLoad=self.songLoaded) self.engine.loadSvgDrawing(self, "background", "keyboard.svg") Dialogs.showLoadingScreen(self.engine, lambda: self.song, text=_("Chilling..."))
def checkParts(self): info = Song.loadSongInfo(self.engine, self.songName, library=self.libraryName) guitars = [] drums = [] vocals = [] for part in info.parts: if part.id == 4 or part.id == 7: drums.append(part) elif part.id == 5: vocals.append(part) else: guitars.append(part) if len(drums) == 0 and self.engine.input.gameDrums > 0: Dialogs.showMessage( self.engine, _("There are no drum parts in this song. Change your controllers to play.") ) return False if len(guitars) == 0 and self.engine.input.gameGuitars > 0: Dialogs.showMessage( self.engine, _("There are no guitar parts in this song. Change your controllers to play.") ) return False if len(vocals) == 0 and self.engine.input.gameMics > 0: Dialogs.showMessage( self.engine, _("There are no vocal parts in this song. Change your controllers to play.") ) return False return True
def __init__(self, skrn, musicPlayer): self.skrn = skrn self.musicPlayer = musicPlayer self.topLeft = (225, 75) self.topRight = (525, 75) self.botRight = (575, 125) self.botLeft = (275, 125) songs = [Song(f) for f in os.listdir(CWD + '/Media/Music/')] self.albumManager = AlbumManager(songs) self.musicPlayer.playPlaylist(self.albumManager.albums[0]) self.albumButtons = [] self.buttonHeight = 25 self.buttonYOffset = 25 self.scrolling = False self.scrollOffset = 0 for x in range(len(self.albumManager.albums)): p1 = (self.botLeft[0], 100 + self.buttonYOffset + (1+x)*self.buttonHeight + 10*x) p2 = (self.topRight[0], 100 + self.buttonYOffset + (1+x)*self.buttonHeight + 10*x) p3 = (self.botRight[0]-1, 125 + self.buttonYOffset + (1+x)*self.buttonHeight + 10*x) p4 = (self.botLeft[0], 125 + self.buttonYOffset + (1+x)*self.buttonHeight + 10*x) self.albumButtons.append(AlbumButton(self.skrn, self, self.albumManager.getAlbum(x).name, (p1, p2, p3, p4), self.setAlbum, x)) self.yOffset = SmartValue(-150 - (self.buttonHeight+self.buttonYOffset)*len(self.albumButtons)) self.points = self.getPoints() self.animateState = -1 print(self.albumManager.albums[0].getLength())
def previewSong(self): self.previewLoaded = True if isinstance(self.selectedItem, Song.SongInfo): song = self.selectedItem.songName # TODO: SongDB else: return if self.careerMode and self.selectedItem.getLocked(): # TODO: SongDB if self.song: self.song.fadeout(1000) return if self.songLoader: try: self.songLoader.stop() except: self.songLoader = None self.songLoader = self.engine.resource.load( self, None, lambda: Song.loadSong(self.engine, song, playbackOnly=True, library=self.library), synch=True, onLoad=self.songLoaded, onCancel=self.songCanceled, )
async def enqueue(ctx): global playqueue split = ctx.message.content.split(" ") link = split[1] music = Song.Song(link, ctx.message.channel, ctx.message.author) await displayembed("Enqueue", ctx) playqueue.append(music) return
def add_song(self, a_song): #if a_song is an instance of the Song class, just append it to the #list if isinstance(a_song, Song): #The song should have the name of the CD as the name of the album if a_song.get_album() == self._album: self._songs.append(a_song) #If the song doesn't have the same title, it doesn't belong else: raise Exception(a_song.get_title() + " is not on " + self._album + " album.") #if a_song is just a song title, create an instance of the Song #class and set the title. Leave the other fields blank else: new_song = Song() new_song.set_title(a_song) return
def loadSongs(self, libraries): Log.debug("Loading songs in %s" % self.library) self.engine.resource.load( self, "songs", lambda: Song.getAvailableSongsAndTitles(self.engine, self.library, progressCallback=self.progressCallback), onLoad=self.prepareSetlist, synch=True, )
def __init__(self, pin=NO_PIN, song=None): self.isRecording = False self.song = Song.Song() if song is None else song self.pin = pin if (self.pin != KeyRecord.NO_PIN): GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(pin, GPIO.OUT)
def loadPlaylist(self): playlistFile = open(MEDIA_PATH + 'Playlists/' + self.name, 'r') lines = playlistFile.read().split('\n') playlistFile.close() for line in lines: if len(line) < 2: break self.songs.append(Song(line)) self.size = len(self.songs)
def slowSearch(snippet): ''' This function takes a snippet searches throuh the library by comparing the local periodograms without a special signature. Keyword argument: snippet -- A given snippet, coming from the IO module with the given information about signal, sampling_rate, ''' # Obtain the size of the snippet snippet_signal = snippet['audio_signal'] snippet_name = snippet['audio_name'] sampling_rate = snippet['sampling_rate'] snippet_address = snippet['audio_source'] # Construct a Song Object called snippet_song snippet_song = Song.Song(snippet_signal, title_info=snippet_name, address_info=snippet_address, sampling_rate_info=sampling_rate) snippet_spectra = snippet_song.get_spectrogram() # Deserialize song_lib and search through periodograms in # song_lib with open('song_lib.pickle', 'rb') as handle: song_lib = pickle.load(handle) # Search through the whole library and compare the snippet # with every song. for song in song_lib: # Get the song's spectrogram hf = h5py.File(song_lib[song]['h5_address'], 'r') song_spectra = hf['spectrogram'][()] hf.close() # Compare the song's spectrogram with the snippet's # spectrogram for i in range(snippet_spectra.shape[1]-6): for j in range(song_spectra.shape[1]-6): # Calculate the cosine similarity between local periodogram initial_similarity = 1 - spatial.distance.cosine( snippet_spectra[:, i], song_spectra[:, j]) # If the similarity is bigger than 75%, then we will search # through the successive window and determine if we had a match if initial_similarity >= .75: successive_similarity = [spatial.distance.cosine( snippet_spectra[:, i+k], song_spectra[:, j+k]) for k in range(1, 6)] successive_similarity = [1 - s for s in successive_similarity] if min(successive_similarity) >= 0.7: # matching_rslt = 'The snippet finds a match!' print("""The snippet finds a match!. The matching song is: \n""") print(song) return(library_read(song)) print("The snippet doesn't find a match in the library.")
def getSong(self, songName): try: for song in self.allSongs: if (song.getName() == songName): print("Song already imported.") return 1 self.allSongs.append(Song(songName)) return 0 except: return 1
def loadLibrary(self): Log.debug("Loading libraries in %s" % self.library) self.loaded = False self.tiersPresent = False if self.splash: Dialogs.changeLoadingSplashScreenText(self.engine, self.splash, _("Browsing Collection...")) else: self.splash = Dialogs.showLoadingSplashScreen(self.engine, _("Browsing Collection...")) self.loadStartTime = time.time() self.engine.resource.load(self, "libraries", lambda: Song.getAvailableLibraries(self.engine, self.library), onLoad = self.loadSongs, synch = True)
def loadCollection(self): self.loaded = False self.engine.resource.load( self, "libraries", lambda: Song.getAvailableLibraries(self.engine, self.library), onLoad=self.libraryListLoaded) showLoadingScreen(self.engine, lambda: self.loaded, text=_("Browsing Collection..."))
def Add(song, title=None, artist_info=None): song = IO.audio_to_signal(song) if title is None: title = song['audio_name'] song = Song.Song(song['audio_signal'], sampling_rate_info=song['sampling_rate'], address_info=song['audio_source'], title_info=title, artist_info=artist_info) DbManager.library_add(song)
def startQueue(self): firstSong = self.songQueue.nextSong(0) Config.set("game", "selected_song", firstSong[0]) Config.set("game", "selected_library", firstSong[1]) Config.set("game", "selected_players", firstSong[2]) self.player.difficulty = firstSong[3] self.player2.difficulty = firstSong[4] self.player.part = firstSong[5] self.player2.part = firstSong[6] self.info = Song.loadSongInfo(self.engine, firstSong[0]) self.songName = firstSong[0] self.startGame(queueCounter = 1)
def populateFromDirectory(self): self.songs = [] self.songCount = 0 for root, dirs, files in os.walk(self.musicDirectory): for element in files: if element.endswith(MP3): self.songCount = self.songCount + 1 mp3Index = len(element) - len(MP3) name = element[:mp3Index] slashIndex = len(self.musicDirectory) + len(SLASH) path = root[slashIndex:] + SLASH self.songs.append(Song(name, path))
def startQueue(self): firstSong = self.songQueue.nextSong(0) Config.set("game", "selected_song", firstSong[0]) Config.set("game", "selected_library", firstSong[1]) Config.set("game", "selected_players", firstSong[2]) self.player.difficulty = firstSong[3] self.player2.difficulty = firstSong[4] self.player.part = firstSong[5] self.player2.part = firstSong[6] self.info = Song.loadSongInfo(self.engine, firstSong[0]) self.songName = firstSong[0] self.startGame(queueCounter=1)
def startQueue(self): #obviously a fair amount of work to be done on this anyway... But note that startGame will not work. firstSong = self.songQueue.nextSong(0) Config.set("game", "selected_song", firstSong[0]) Config.set("game", "selected_library", firstSong[1]) Config.set("game", "selected_players", firstSong[2]) self.player.difficulty = firstSong[3] self.player2.difficulty = firstSong[4] self.player.part = firstSong[5] self.player2.part = firstSong[6] self.info = Song.loadSongInfo(self.engine, firstSong[0]) self.songName = firstSong[0] self.startGame(queueCounter = 1)
async def enqueue(ctx): global playqueue try: split = ctx.message.content.split(" ") split = split[1] split = split.split("&") link = split[0] music = Song.Song(link, ctx.message.channel, ctx.message.author) await displayembed("Enqueue",ctx) playqueue.append(music) except Exception as e: await write_errors("Exception occured in enqueue: {0} at {1}".format(e, str(datetime.now()))) return
def onSubmitEvent(self, mode, recordName, playbackName): self.recordName = recordName self.playbackName = playbackName if (mode == gui.Mode.FREEPLAY): self.keyboard.play() elif (mode == gui.Mode.RECORD): self.keyboard.play() self.recorder.record() elif (mode == gui.Mode.PLAYBACK): self.playback.play(Song.load(playbackName)) elif (mode == gui.Mode.MUTE): self.keyboard.stop()
def startQueue(self): #obviously a fair amount of work to be done on this anyway... But note that startGame will not work. firstSong = self.songQueue.nextSong(0) Config.set("game", "selected_song", firstSong[0]) Config.set("game", "selected_library", firstSong[1]) Config.set("game", "selected_players", firstSong[2]) self.player.difficulty = firstSong[3] self.player2.difficulty = firstSong[4] self.player.part = firstSong[5] self.player2.part = firstSong[6] self.info = Song.loadSongInfo(self.engine, firstSong[0]) self.songName = firstSong[0] self.startGame(queueCounter=1)
def AutoMusic(self, parent, page_type, loadpic, waitpic, incontainer, outcontainer, records, music): """ This is a callback function for 'Generate' button. It takes the selected inputs from the listbox, make an AutoComposeSong object, and execute its functions to output a MIDI file. * See 'AutoComposeSong.py' for the detailed explanation on how these methods work. """ genre = self.genreList[int(self.gr_listbox.curselection()[0])] key = eval(self.keyList[int(self.key_listbox.curselection()[0])]) cp = self.cpList[int(self.cp_listbox.curselection()[0])] title = self.title.get() mode = Tonics numPhrase = 4 beat = 72 if self.entry_field.get() == '': userInput = [] else: userInput = Song() userInput.reset() userInputMelody = wrapNote(self.entry_field.get().split('-')) userInputTimes = constant_times(userInputMelody, 2, beat) userInput.wrapNotesAndTimes(userInputMelody, userInputTimes) autoSong = AutoComposeSong() autoSong.reset() autoSong.setTitle(title) autoSong.setup(genre, key, mode, cp, numPhrase, beat, userInput) autoSong.exportMidi(1, 'Output MIDIs/' + title + '.mid') self.page_factory(parent, page_type, loadpic, waitpic, incontainer, outcontainer, records, autoSong)
def scan_songs(path): songs = [] for root, directories, filenames in os.walk(path): for filename in filenames: path = os.path.join(root, filename) tag = id3.Tag() tag.parse(path) album = tag.album artist = tag.artist title = tag.title genre = tag.genre song = Song(title, path, artist, album, genre) songs.append(song) return songs
def loadSongs(self): s = [] sList = [] f = open("Song_Info.txt",'r') lines = f.readlines() for line in lines: info = line.split("$") if len(info) != 6: print "[!] Corrupted Song_Info file! You may want to recreate the file with the command \"restore\"" continue info[len(info)-1] = info[len(info)-1].split(":") sList.append(info[0].lower()) s.append(Song(info[3],info[1],info[0],info[2],info[5],info[4])) return s,sList
def clickPlay(self, listbox1): #play a song if something is selected in the listbox try: if listbox1.get(listbox1.curselection()) != "": selectedSongTitle = listbox1.get(listbox1.curselection()) selectedSongPath = self.mp3_object.getPath( ) + "/" + selectedSongTitle selectedSong = Song.Song(selectedSongPath) self.mp3_object.normalPlay(selectedSong) #will throw error if nothing is selected. If this happens, play normal except: firstSong = self.mp3_object.getMusicLibrary()[0] self.mp3_object.normalPlay(firstSong)
def populateFromFile(self): self.songs = [] self.songCount = 0 fileObj = FileHandler(self.directory, "Songs") fileString = fileObj.read() tokenizer = StringTokenizer(NEWLINE) tokenizer.setString(fileString) while not tokenizer.atEnd(): self.songCount = self.songCount + 1 token = tokenizer.getToken() index = token.index("/,") name = token[index + 2:] path = token[:index + 1] self.songs.append(Song(name, path))
def playSelectedSong(self): song = self.getSelectedSong() if not song: return if self.songLoader: self.songLoader.cancel() # Don't start a new song loader until the previous one is finished if self.songLoader.isAlive(): self.songCountdown = 256 return if self.song: self.song.fadeout(1000) self.songLoader = self.engine.resource.load(self, None, lambda: Song.loadSong(self.engine, song, playbackOnly = True, library = self.library), onLoad = self.songLoaded)
def getSongs_MSD(MSD_data_folder_path): rootdir = MSD_data_folder_path song_list = [] count = 0 for subdir, dirs, files in os.walk(rootdir): for file in files: filepath = subdir + os.sep + file if filepath.endswith(".h5"): f = h5.File(filepath, "r") songDict = getSongAttributes_MSD(f) song = Song.Song(songDict) song_list.append(song) count += 1 if count % 500 == 0: print "processed %d songs..." % count print "Successfully extracted %d songs." % count return song_list
def scrape_songs(self, page_num=0): song_list = [] url = self.url + str(page_num) + "/" response = get(url, timeout=5) content = BeautifulSoup(response.content, "html.parser") # Loop for each song on the current page for song in content.findAll("div", {"class" : "grid-item song"}): throwback = False song_name = song.find("a", {"class" : "cover-title grid-item-title"}).text.strip() # May be a song made by a group of artists for group in song.findAll("div", {"class" : "grid-item-artists"}): artists = group.findAll("em", {"class" : "default-artist"}) main_artists = "".join([individual.text.strip() + " " for individual in artists]).strip() # Extract feature artist(s) if any features_list = [] for feature in group.findAll("em", {"class" : "no-bold"}): if feature not in self.excluded: features_list.append(feature.text.strip()) features_string = ", ".join(features_list) # Extract the release date of the song & find out if this is a throwback for meta_data in song.findAll("div", {"class" : "grid-item-meta-info hidden-md-down"}): for tag in meta_data.findAll("span", {"class" : "song-review"}): if (tag.text == "THROWBACK"): throwback = True for time in meta_data.findAll("span", {"class" : "grid-item-time song pull-right"}): release_date = self.format_date(time.findAll("span")[0].text.strip()) # Extract the link to the song page prefix = "https://www.hotnewhiphop.com" for link in song.findAll("a", {"class" : "cover-title grid-item-title"}, href=True): song_page = prefix + link["href"] # Append to song list if (not throwback): song_list.append(Song(song_name, main_artists, features_string, release_date, song_page, features_list)) else: print("Throwback:\t {} : {} : {}".format(main_artists, song_name, song_page)) # Return list of Song objects return song_list
def playSelectedSong(self, forceplay = 0): song = self.getSelectedSong() if not song or (not self.autoPreview and not forceplay): return if self.songLoader: self.songLoader.cancel() # Don't start a new song loader until the previous one is finished if self.songLoader.isAlive(): self.songCountdown = 256 return if self.song: self.playSongName = "" self.song.fadeout(1000) self.song = None self.songLoader = self.engine.resource.load(self, None, lambda: Song.loadSong(self.engine, song, playbackOnly = True, library = self.library), onLoad = self.songLoaded) self.playSongName = self.getSelectedSong()
def import_From_Playlist(self, playlist): songs = [] for i in range(0, len(playlist.playlist_song_names)): song_attributes = { "accousticness": playlist.playlist_accousticness[i], "artist_name": playlist.playlist_song_artists[i], "cluster_id": 9999, # cluster_id = 9999 indicates not clustered "danceability": playlist.playlist_dancibility[i], "energy": playlist.playlist_energy[i], "from_playlist": playlist.playlist_playlistname, "instrumentalness": playlist.playlist_instrumentalness[i], "loudness": playlist.playlist_loudness[i], "speechiness": playlist.playlist_speechness[i], "tempo": playlist.playlist_tempo[i], "title": playlist.playlist_song_names[i], "valence": playlist.playlist_valence[i] } song = Song(song_attributes) songs.append(song) self.insert_Songs(songs)
def createClient(self, libraryName, songName): self.libraryName = libraryName self.songName = songName self.stars = 0 self.accuracy = 0 self.counter = 0 self.showHighscores = False self.highscoreIndex = None self.taunt = None self.uploadingScores = False self.nextScene = None items = [ (_("Replay"), self.replay), (_("Change Song"), self.changeSong), (_("Quit to Main Menu"), self.quit), ] self.menu = Menu(self.engine, items, onCancel = self.quit, pos = (.2, .5)) self.engine.resource.load(self, "song", lambda: Song.loadSong(self.engine, songName, library = self.libraryName, notesOnly = True), onLoad = self.songLoaded) self.engine.loadSvgDrawing(self, "background", "keyboard.svg") Dialogs.showLoadingScreen(self.engine, lambda: self.song, text = _("Chilling..."))
def createClient(self, libraryName, songName, players = 1): #players = None self.logClassInits = self.engine.config.get("game", "log_class_inits") if self.logClassInits == 1: Log.debug("GameResultsSceneClient class init...") self.libraryName = libraryName self.songName = songName self.stars = [0 for i in players] self.accuracy = [0 for i in players] self.counter = 0 self.showHighscores = False self.highscoreIndex = [-1 for i in players] self.taunt = None self.uploadingScores = [False for p in players] self.highScoreResult = [None for p in players] self.resultNum = 0 self.uploadResult = None self.nextScene = None self.offset = None self.pauseScroll = None self.scorePart = None self.scoreDifficulty = None self.playerList = players self.spinnyDisabled = True#NO SPINNY!!! self.scoreScrollStartOffset = .8 #MFH - where highscore scrolling starts #MFH - pretranslation self.tsSettings = _("settings") self.tsHopos = _("HOPOs") self.tsHitWindow = _("Hit Window") #myfingershurt: reordering so default is Change Song. items = [ (_("Continue"), self.changeSong), (_("Replay"), self.replay), (_("Quit"), self.quit), ] self.menu = Menu(self.engine, items, onCancel = self.quit, pos = (.2, .5)) self.engine.resource.load(self, "song", lambda: Song.loadSong(self.engine, songName, library = self.libraryName, notesOnly = True, part = [player.part for player in self.playerList]), onLoad = self.songLoaded) #Get theme themename = self.engine.data.themeLabel #now theme determination logic is only in data.py: self.theme = self.engine.data.theme self.starScoring = self.engine.config.get("game", "star_scoring")#MFH self.Congratphrase = self.engine.config.get("game", "congrats")#blazingamer self.resultCheerLoop = self.engine.config.get("game", "result_cheer_loop")#MFH #MFH theme.ini override: self.cheerLoopDelay = Theme.crowdLoopDelay if self.cheerLoopDelay == None: self.cheerLoopDelay = self.engine.config.get("game", "cheer_loop_delay")#MFH Log.debug("Cheer loop delay value used: %d" % self.cheerLoopDelay) self.cheerLoopCounter = self.cheerLoopDelay #MFH - starts out ready to cheer #MFH self.hopoStyle = self.engine.config.get("game", "hopo_style") if self.hopoStyle == 0: self.hopoStyle = _("None") elif self.hopoStyle == 1: self.hopoStyle = _("RF-Mod") elif self.hopoStyle == 2: self.hopoStyle = _("GH2 Strict") elif self.hopoStyle == 3: self.hopoStyle = _("GH2 Sloppy") elif self.hopoStyle == 4: self.hopoStyle = _("GH2") self.hopoFreq = self.engine.config.get("coffee", "moreHopo") #MFH if song.ini HOPO frequency exists and is enabled, display that instead... self.songHopoFreq = self.engine.config.get("game", "song_hopo_freq") songHopoFreq = self.playerList[0].hopoFreq try: songHopoFreq = int(songHopoFreq) except Exception, e: songHopoFreq = None
def load_songs(self): self.song_list.append(Song.Song(1, "Music/EastCoast/Long Cool Woman.mp3", 139)) self.song_list.append(Song.Song(2, "Music/EastCoast/Tush.mp3", 145))
def __init__(self, engine, songName = None): self.engine = engine self.time = 0.0 self.offset = 1.0 self.songLoader = self.engine.resource.load(self, "song", lambda: Song.loadSong(self.engine, "defy", playbackOnly = True), onLoad = self.songLoaded) self.engine.loadImgDrawing(self, "background1", "editor.png") self.engine.loadImgDrawing(self, "background2", "keyboard.png") self.engine.loadImgDrawing(self, "background3", "cassette.png") nf = self.engine.data.font bf = self.engine.data.bigFont ns = 0.002 bs = 0.001 hs = 0.003 c1 = (1, 1, .5, 1) c2 = (1, .75, 0, 1) space = Text(nf, hs, c1, "center", " ") self.credits = [ Text(nf, ns, c2, "center", _("Unreal Voodoo")), Text(nf, ns, c1, "center", _("presents")), Text(nf, bs, c2, "center", " "), Picture(self.engine, "logo.png", .25), Text(nf, bs, c2, "center", " "), Text(nf, bs, c2, "center", _("Version %s") % Version.version()), space, Text(nf, ns, c1, "left", _("Game Design,")), Text(nf, ns, c1, "left", _("Programming:")), Text(nf, ns, c2, "right", "Sami Kyostila"), space, Text(nf, ns, c1, "left", _("Music,")), Text(nf, ns, c1, "left", _("Sound Effects:")), Text(nf, ns, c2, "right", "Tommi Inkila"), space, Text(nf, ns, c1, "left", _("Graphics:")), Text(nf, ns, c2, "right", "Joonas Kerttula"), space, Text(nf, ns, c1, "left", _("Introducing:")), Text(nf, ns, c2, "right", "Mikko Korkiakoski"), Text(nf, ns, c2, "right", _("as Jurgen, Your New God")), space, Text(nf, ns, c2, "right", "Marjo Hakkinen"), Text(nf, ns, c2, "right", _("as Groupie")), space, Text(nf, ns, c1, "left", _("Song Credits:")), Text(nf, ns, c2, "right", _("Bang Bang, Mystery Man")), Text(nf, bs, c2, "right", _("music by Mary Jo and Tommi Inkila")), Text(nf, bs, c2, "right", _("lyrics by Mary Jo")), space, Text(nf, ns, c2, "right", _("Defy The Machine")), Text(nf, bs, c2, "right", _("music by Tommi Inkila")), space, Text(nf, ns, c2, "right", _("This Week I've Been")), Text(nf, ns, c2, "right", _("Mostly Playing Guitar")), Text(nf, bs, c2, "right", _("composed and performed by Tommi Inkila")), space, Text(nf, ns, c1, "left", _("Testing:")), Text(nf, ns, c2, "right", "Mikko Korkiakoski"), Text(nf, ns, c2, "right", "Tomi Kyostila"), Text(nf, ns, c2, "right", "Jani Vaarala"), Text(nf, ns, c2, "right", "Juho Jamsa"), Text(nf, ns, c2, "right", "Olli Jakola"), space, Text(nf, ns, c1, "left", _("Mac OS X port:")), Text(nf, ns, c2, "right", "Tero Pihlajakoski"), space, Text(nf, ns, c1, "left", _("Special thanks to:")), Text(nf, ns, c2, "right", "Tutorial inspired by adam02"), space, Text(nf, ns, c1, "left", _("Made with:")), Text(nf, ns, c2, "right", "Python"), Text(nf, bs, c2, "right", "http://www.python.org"), space, Text(nf, ns, c2, "right", "PyGame"), Text(nf, bs, c2, "right", "http://www.pygame.org"), space, Text(nf, ns, c2, "right", "PyOpenGL"), Text(nf, bs, c2, "right", "http://pyopengl.sourceforge.net"), space, Text(nf, ns, c2, "right", "Amanith Framework"), Text(nf, bs, c2, "right", "http://www.amanith.org"), space, Text(nf, ns, c2, "right", "Illusoft Collada module 1.4"), Text(nf, bs, c2, "right", "http://colladablender.illusoft.com"), space, Text(nf, ns, c2, "right", "MXM Python Midi Package 0.1.4"), Text(nf, bs, c2, "right", "http://www.mxm.dk/products/public/pythonmidi"), space, space, Text(nf, bs, c1, "center", _("Source Code available under the GNU General Public License")), Text(nf, bs, c2, "center", "http://www.unrealvoodoo.org"), space, space, space, space, Text(nf, bs, c1, "center", _("Copyright 2006-2008 by Unreal Voodoo")), ]
def run(self, ticks): SceneClient.run(self, ticks) players = 1 if not self.wizardStarted: self.wizardStarted = True if not self.songName: while 1: if self.engine.cmdPlay == 2: self.songName = Config.get("game", "selected_song") self.libraryName = Config.get("game", "selected_library") else: self.mode = 1 self.libraryName, self.songName = \ Dialogs.chooseSong(self.engine, \ selectedLibrary = Config.get("game", "selected_library"), selectedSong = Config.get("game", "selected_song")) if self.libraryName == None: newPath = Dialogs.chooseFile(self.engine, masks = ["*/songs"], prompt = _("Choose a new songs directory."), dirSelect = True) if newPath != None: Config.set("game", "base_library", os.path.dirname(newPath)) Config.set("game", "selected_library", "songs") Config.set("game", "selected_song", "") self.engine.resource.refreshBaseLib() #myfingershurt - to let user continue with new songpath without restart if not self.songName: self.session.world.finishGame() return if not self.tut: Config.set("game", "selected_library", self.libraryName) Config.set("game", "selected_song", self.songName) self.mode = 2 info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) selected = False escape = False escaped = False #while True: #this nesting is now useless #MFH - add "Practice" mode, which will activate a section selection menu before "part" #racer: main menu instead of second menu practice #self.player.practiceMode = Player.PracticeSet #MFH - parameters for newLocalGame: #players = -1 (party mode), 1, 2 #mode1p = 0 (quickplay), 1 (practice), 2 (career) #mode2p = 0 (face-off), 1 (pro face-off) #Config.define("game", "players", int, 1) #Config.define("game","game_mode", int, 0) #Config.define("game","multiplayer_mode", int, 0) if Config.get("game","game_mode") == 1 and Config.get("game","players") == 1: #practice mode self.player.practiceMode = True else: self.player.practiceMode = False slowDownDivisor = Config.get("audio", "speed_factor") while 1: #new nesting for Practice Mode - section / start time selection if self.player.practiceMode: values, options = Config.getOptions("audio", "speed_factor") if self.subMenuPosTuple: slowdown = Dialogs.chooseItem(self.engine, options, "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("Speed Select:")), pos = self.subMenuPosTuple) else: slowdown = Dialogs.chooseItem(self.engine, options, "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("Speed Select:"))) for i in range(len(values)): if options[i] == slowdown: self.player.practiceSpeed = values[i] slowDownDivisor = values[i] break if self.player.practiceMode: sectionLabels = [sLabel for sLabel,sPos in info.sections] if self.subMenuPosTuple: startLabel = Dialogs.chooseItem(self.engine, sectionLabels, "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("Start Section:")), pos = self.subMenuPosTuple) else: startLabel = Dialogs.chooseItem(self.engine, sectionLabels, "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("Start Section:"))) if startLabel: Log.debug("Practice start section selected: " + startLabel) else: startLabel = "Gig" if startLabel: self.player.practiceSection = startLabel #find start position in array: try: tempStart = [sPos for sLabel,sPos in info.sections if sLabel == startLabel] if tempStart == []: self.player.startPos = 0.0 else: self.player.startPos = tempStart[0] Log.debug("Practice start position retrieved: " + str(self.player.startPos)) except: Log.error("Cannot retrieve start position!") self.player.startPos = 0.0 break else: #self.player.startPos = 0.0 break; guitars = [] drums = [] vocals = [] autoPart = None for part in info.parts: if part.id == 4: drums.append(part) elif part.id == 5: vocals.append(part) else: guitars.append(part) if self.engine.cmdPlay == 2 and self.engine.cmdPart is not None and len(self.playerList) == 1: if self.engine.cmdPart == part.id: Log.debug("Command-line mode: Part found!") if part.id == 4 and self.engine.input.gameDrums > 0: autoPart = part.id elif part.id == 5 and self.engine.input.gameMics > 0: autoPart = part.id elif self.engine.input.gameGuitars > 0: autoPart = part.id if autoPart is None: if len(drums) == 0 and self.engine.input.gameDrums > 0: Dialogs.showMessage(self.engine, _("There are no drum parts in this song. Change your controllers to play.")) escaped = True if self.engine.cmdPlay == 2: self.engine.cmdPlay = 0 break if len(guitars) == 0 and self.engine.input.gameGuitars > 0: Dialogs.showMessage(self.engine, _("There are no guitar parts in this song. Change your controllers to play.")) escaped = True if self.engine.cmdPlay == 2: self.engine.cmdPlay = 0 break if len(vocals) == 0 and self.engine.input.gameMics > 0: Dialogs.showMessage(self.engine, _("There are no vocal parts in this song. Change your controllers to play.")) escaped = True if self.engine.cmdPlay == 2: self.engine.cmdPlay = 0 break for i, player in enumerate(self.playerList): while 1: #new nesting for Practice Mode selection selectedPlayer = False choose = [] if player.controlType == 2 or player.controlType == 3: choose = drums elif player.controlType == 5: choose = vocals else: choose = guitars if len(choose) > 1: if self.subMenuPosTuple: p = Dialogs.chooseItem(self.engine, choose, "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("%s Choose a part:") % player.name), selected = player.part, pos = self.subMenuPosTuple) else: p = Dialogs.chooseItem(self.engine, choose, "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("%s Choose a part:") % player.name), selected = player.part) else: p = choose[0] if p: player.part = p else: if not player.practiceMode: escaped = True break; while 1: if len(info.partDifficulties[p.id]) > 1: if self.subMenuPosTuple: d = Dialogs.chooseItem(self.engine, info.partDifficulties[p.id], "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("%s Choose a difficulty:") % player.name), selected = player.difficulty, pos = self.subMenuPosTuple) else: d = Dialogs.chooseItem(self.engine, info.partDifficulties[p.id], "%s \n %s" % (Dialogs.removeSongOrderPrefixFromName(info.name), _("%s Choose a difficulty:") % player.name), selected = player.difficulty) else: try: d = info.partDifficulties[p.id][0] except: # Bug : nothing inside... d = None pass if d: player.difficulty = d selectedPlayer = True else: if len(choose) <= 1: #escape = True escaped = True break if selectedPlayer: break if selectedPlayer or escaped: break #if selected or escaped: #new nesting for Practice Mode selection if selected or escaped: #new nesting for Practice Mode selection break else: selected = True if selected or escaped: #new nesting for Practice Mode section selection break else: self.playerList[0].part = Song.parts[autoPart] for diff in info.partDifficulties[autoPart]: if self.engine.cmdDiff == diff.id: self.playerList[0].difficulty = diff break else: self.playerList[0].difficulty = info.partDifficulties[autoPart][0] selected = True break if (not selected) or escape: continue break else: #evilynux - Fixes Practice Mode from the cmdline if Config.get("game","game_mode") == 1 and Config.get("game","players") == 1: self.player.practiceMode = True info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) if self.engine.cmdPlay == 3: if len(info.parts) >= self.engine.cmdPart: self.player.part = info.parts[self.engine.cmdPart] if len(info.partDifficulties[self.player.part.id]) >= self.engine.cmdDiff: self.player.difficulty = info.partDifficulties[self.player.part.id][self.engine.cmdDiff] # Make sure the difficulty we chose is available if not self.player.part in info.parts: self.player.part = info.parts[0] if not self.player.difficulty in info.partDifficulties[self.player.part.id]: self.player.difficulty = info.partDifficulties[self.player.part.id][0] if not self.engine.createdGuitarScene: if self.engine.cmdPlay > 0: self.engine.cmdPlay = 3 #self.engine.createdGuitarScene = True self.session.world.deleteScene(self) self.session.world.createScene("GuitarScene", libraryName = self.libraryName, songName = self.songName, Players = players)
class ThreadedMusicTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass def initMusicServer(HOST, PORT, pl): global playlist playlist = pl try: server = ThreadedMusicTCPServer((HOST, PORT), ThreadedTCPRequestHandler) ip, port = server.server_address server_thread = threading.Thread(target=server.serve_forever) server_thread.setDaemon(True) server_thread.start() print "Server loop running in thread:", server_thread.getName() #server_thread.join() except KeyboardInterrupt, e: return if __name__ == "__main__": from Song import * # Port 0 means to select an arbitrary unused port HOST, PORT = "localhost", 9999 s = Song("Across the Universe", "Fiona Apple", "PleasantVille") s.id = 10 playlist = {10 : s} initMusicServer(HOST, PORT, playlist) print "end of main"
def libraryListLoaded(self, libraries): self.engine.resource.load(self, "songs", lambda: Song.getAvailableSongs(self.engine, self.library), onLoad = self.songListLoaded)
from NoteSequence import * from MidiNote import * def initialSongUI(): trackCount = raw_input('Enter track count: ') tempo = raw_input('Enter a tempo: ') key = raw_input('Enter a key: ') length = raw_input('Enter a song length: ') return (int(trackCount), int(tempo), str(key), str(length)) #Supports up to four tracks #TODO: Make this a little more elegant def determineVoice(currentTrackCount): if currentTrackCount == 0: return ALTO if currentTrackCount == 1: return BASS if currentTrackCount == 2: return SOPRANO if currentTrackCount == 3: return TENOR if __name__ == '__main__': choices = initialSongUI() song = Song(choices[0], #Track Count choices[1]) #Tempo key = choices[2] #Key length = int(choices[3]) #Length for i in range(song.trackCount): seq = NoteSequence(key, determineVoice(i), length) seq.writeSequenceToTrack(song, i) song.markSongEnd() midi.write_midifile("example.mid", song.pattern)
return wrapNote(notes) if __name__ == '__main__': autoSong = AutoComposeSong('Test') # Example Inputs genre = 'New Age' key = B mode = Tonics chordProgression = CP2 numPhrase = 80 beat = 48 # Excerpt from 'River Flows in You', by Yiruma inputNotes = wrapNote([69, 68, 69, 68, 69, 64, 69, 62]) inputTimes = [72, 144, 216, 288, 360, 432, 504, 578] userInput = Song() userInput.wrapNotesAndTimes(inputNotes, inputTimes) userInput = [] # Export the Automated Song autoSong.setup(genre, key, mode, chordProgression, numPhrase, beat, userInput) autoSong.exportMidi(1, 'TEST.mid') print autoSong
def run(self, ticks): SceneClient.run(self, ticks) players = 1 if not self.wizardStarted: self.wizardStarted = True if self.engine.cmdPlay == 1: self.songName = Config.get("game", "selected_song") self.libraryName = Config.get("game", "selected_library") self.engine.cmdPlay = 2 if not self.songName: while True: self.libraryName, self.songName = \ Dialogs.chooseSong(self.engine, \ selectedLibrary = Config.get("game", "selected_library"), selectedSong = Config.get("game", "selected_song")) if self.libraryName == None: newPath = Dialogs.chooseFile(self.engine, masks = ["*/songs"], prompt = _("Choose a new songs directory."), dirSelect = True) if newPath != None: Config.set("game", "base_library", os.path.dirname(newPath)) Config.set("game", "selected_library", "songs") Config.set("game", "selected_song", "") if not self.songName: self.session.world.finishGame() return Config.set("game", "selected_library", self.libraryName) Config.set("game", "selected_song", self.songName) info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) selected = False escape = False escaped = False while True: if len(info.parts) > 1: p = Dialogs.chooseItem(self.engine, info.parts, "%s \n %s" % (info.name, _("Player 1 Choose a part:")), selected = self.player.part) else: p = info.parts[0] if p: self.player.part = p else: break; while True: if len(info.difficulties) > 1: d = Dialogs.chooseItem(self.engine, info.difficulties, "%s \n %s" % (info.name, _("Player 1 Choose a difficulty:")), selected = self.player.difficulty) else: d = info.difficulties[0] if d: self.player.difficulty = d else: if len(info.parts) <= 1: escape = True break while True: if self.engine.config.get("game", "players") > 1: p = Dialogs.chooseItem(self.engine, info.parts + ["Party Mode"] + ["No Player 2"], "%s \n %s" % (info.name, _("Player 2 Choose a part:")), selected = self.player2.part) if p and p == "No Player 2": players = 1 selected = True self.player2.part = p break elif p and p == "Party Mode": players = -1 selected = True self.player2.part = p break elif p and p != "No Player 2" and p != "Party Mode": players = 2 self.player2.part = p else: if len(info.difficulties) <= 1: escaped = True if len(info.parts) <= 1: escape = True break while True: if len(info.difficulties) > 1: d = Dialogs.chooseItem(self.engine, info.difficulties, "%s \n %s" % (info.name, _("Player 2 Choose a difficulty:")), selected = self.player2.difficulty) else: d = info.difficulties[0] if d: self.player2.difficulty = d else: break selected = True break else: selected = True break if selected: break if selected or escaped: break if selected or escape: break if (not selected) or escape: continue break else: info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) if self.engine.cmdPlay == 2: if len(info.difficulties) >= self.engine.cmdDiff: self.player.difficulty = info.difficulties[self.engine.cmdDiff] if len(info.parts) >= self.engine.cmdPart: self.player.part = info.parts[self.engine.cmdPart] # Make sure the difficulty we chose is available if not self.player.difficulty in info.difficulties: self.player.difficulty = info.difficulties[0] if not self.player.part in info.parts: self.player.part = info.parts[0] if not self.player.difficulty in info.difficulties: self.player.difficulty = info.difficulties[0] if not self.player.part in info.parts: self.player.part = info.parts[0] self.session.world.deleteScene(self) self.session.world.createScene("GuitarScene", libraryName = self.libraryName, songName = self.songName, Players = players)
def prepareSetlist(self, songs): if self.songLoader: self.songLoader.stop() msg = self.engine.setlistMsg self.engine.setlistMsg = None self.selectedIndex = 0 if self.listingMode == 0 or self.careerMode: self.items = self.libraries + self.songs else: self.items = self.songs self.itemRenderAngles = [0.0] * len(self.items) self.itemLabels = [None] * len(self.items) self.searching = False self.searchText = "" shownItems = [] for item in self.items: # remove things we don't want to see. Some redundancy, but that's okay. if isinstance(item, Song.TitleInfo) or isinstance(item, Song.SortTitleInfo): if self.showCareerTiers == 2: if isinstance(item, Song.TitleInfo): if len(shownItems) > 0: if isinstance(shownItems[-1], Song.TitleInfo): shownItems.pop() shownItems.append(item) elif isinstance(item, Song.SortTitleInfo): continue else: if isinstance(item, Song.TitleInfo): continue elif isinstance(item, Song.SortTitleInfo): if not self.showSortTiers: continue if len(shownItems) > 0: if isinstance(shownItems[-1], Song.SortTitleInfo): shownItems.pop() shownItems.append(item) elif isinstance(item, Song.SongInfo): if self.careerMode and (not self.showLockedSongs) and item.getLocked(): continue else: shownItems.append(item) else: shownItems.append(item) if len(shownItems) > 0: if isinstance(shownItems[-1], Song.TitleInfo) or isinstance(shownItems[-1], Song.SortTitleInfo): shownItems.pop() if len(self.items) > 0 and len(shownItems) == 0: msg = _("No songs in this setlist are available to play!") if self.careerMode: msg = msg + " " + _("Make sure you have a working career pack!") Dialogs.showMessage(self.engine, msg) elif len(shownItems) > 0: for item in shownItems: if isinstance(item, Song.SongInfo) or isinstance(item, Song.LibraryInfo): self.items = shownItems # make sure at least one item is selectable break else: msg = _("No songs in this setlist are available to play!") if self.careerMode: msg = msg + " " + _("Make sure you have a working career pack!") Dialogs.showMessage(self.engine, msg) self.items = [] if self.items == []: # MFH: Catch when there ain't a damn thing in the current folder - back out! if self.library != Song.DEFAULT_LIBRARY: Dialogs.hideLoadingSplashScreen(self.engine, self.splash) self.splash = None self.startingSelected = self.library self.library = os.path.dirname(self.library) self.selectedItem = None self.loadLibrary() return Log.debug("Setlist loaded.") self.loaded = True if self.setlistStyle == 1: for i in range(self.headerSkip): self.items.insert(0, Song.BlankSpaceInfo()) for i in range(self.footerSkip): self.items.append(Song.BlankSpaceInfo()) if self.startingSelected is not None: for i, item in enumerate(self.items): if isinstance(item, Song.SongInfo) and self.startingSelected == item.songName: # TODO: SongDB self.selectedIndex = i break elif isinstance(item, Song.LibraryInfo) and self.startingSelected == item.libraryName: self.selectedIndex = i break for item in self.items: if isinstance(item, Song.SongInfo): item.name = Song.removeSongOrderPrefixFromName(item.name) # TODO: I don't like this. elif not self.tiersPresent and (isinstance(item, Song.TitleInfo) or isinstance(item, Song.SortTitleInfo)): self.tiersPresent = True while isinstance(self.items[self.selectedIndex], Song.BlankSpaceInfo) or ( ( isinstance(self.items[self.selectedIndex], Song.TitleInfo) or isinstance(self.items[self.selectedIndex], Song.SortTitleInfo) ) and not self.selectTiers ): self.selectedIndex += 1 if self.selectedIndex >= len(self.items): self.selectedIndex = 0 self.itemRenderAngles = [0.0] * len(self.items) self.itemLabels = [None] * len(self.items) if self.preloadSongLabels: for i in range(len(self.items)): self.loadStartTime = time.time() Dialogs.changeLoadingSplashScreenText(self.engine, self.splash, _("Loading Album Artwork...")) self.loadItemLabel(i, preload=True) self.updateSelection() Dialogs.hideLoadingSplashScreen(self.engine, self.splash) self.splash = None
def libraryListLoaded(self, libraries): self.engine.resource.load(self, "songs", lambda: Song.getAvailableSongs(self.engine, self.library), onLoad = self.songListLoaded)
def checkCmdPlay(self): info = Song.loadSongInfo(self.engine, self.songName, library=self.libraryName) guitars = [] drums = [] vocals = [] autoPart = None for part in info.parts: if part.id == 4 or part.id == 7: drums.append(part) elif part.id == 5: vocals.append(part) else: guitars.append(part) if self.engine.cmdPlay == 2 and self.engine.cmdPart is not None and len(self.playerList) == 1: if self.engine.cmdPart == part.id: Log.debug("Command-line mode: Part found!") if part.id == 4 and self.engine.input.gameDrums > 0: autoPart = part.id elif part.id == 5 and self.engine.input.gameMics > 0: autoPart = part.id elif self.engine.input.gameGuitars > 0: autoPart = part.id if autoPart is None: if len(drums) == 0 and self.engine.input.gameDrums > 0: if self.splash: Dialogs.hideLoadingSplashScreen(self.engine, self.splash) self.splash = None Dialogs.showMessage( self.engine, _("There are no drum parts in this song. Change your controllers to play.") ) if self.engine.cmdPlay == 2: self.engine.cmdPlay = 0 return False if len(guitars) == 0 and self.engine.input.gameGuitars > 0: if self.splash: Dialogs.hideLoadingSplashScreen(self.engine, self.splash) self.splash = None Dialogs.showMessage( self.engine, _("There are no guitar parts in this song. Change your controllers to play.") ) if self.engine.cmdPlay == 2: self.engine.cmdPlay = 0 return False if len(vocals) == 0 and self.engine.input.gameMics > 0: if self.splash: Dialogs.hideLoadingSplashScreen(self.engine, self.splash) self.splash = None Dialogs.showMessage( self.engine, _("There are no vocal parts in this song. Change your controllers to play.") ) if self.engine.cmdPlay == 2: self.engine.cmdPlay = 0 return False # Make sure the difficulty we chose is available p = self.playerList[0].part player = self.playerList[0] if self.engine.cmdDiff is not None: diff = Song.difficulties[self.engine.cmdDiff] if diff in info.partDifficulties[p.id]: self.playerList[0].difficulty = diff else: self.playerList[0].difficulty = info.partDifficulties[p.id][0] else: if self.splash: Dialogs.hideLoadingSplashScreen(self.engine, self.splash) self.splash = None self.playerList[0].difficulty = Dialogs.chooseItem( self.engine, info.partDifficulties[p.id], "%s \n %s" % (Song.removeSongOrderPrefixFromName(info.name), _("%s Choose a difficulty:") % player.name), selected=player.difficulty, ) return True
def loadCollection(self): self.loaded = False self.engine.resource.load(self, "libraries", lambda: Song.getAvailableLibraries(self.engine, self.library), onLoad = self.libraryListLoaded) showLoadingScreen(self.engine, lambda: self.loaded, text = _("Browsing Collection..."))
def __init__(self, engine, libraryName=None, songName=None): Scene.__init__(self, engine) if self.engine.world.sceneName == "SongChoosingScene": # MFH - dual / triple loading cycle fix Log.warn("Extra SongChoosingScene was instantiated, but detected and shut down. Cause unknown.") raise SuppressScene # stump else: self.engine.world.sceneName = "SongChoosingScene" if self.engine.config.get("debug", "use_new_song_database"): Song.updateSongDatabase(self.engine) self.wizardStarted = False self.libraryName = libraryName self.songName = songName if not self.libraryName: self.libraryName = self.engine.config.get("setlist", "selected_library") if not self.libraryName: self.libraryName = Song.DEFAULT_LIBRARY if not self.songName: self.songName = self.engine.config.get("setlist", "selected_song") self.gameMode = self.engine.world.gameMode self.careerMode = self.gameMode == CAREER self.practiceMode = self.gameMode == PRACTICE self.gameMode2p = self.engine.world.multiMode self.autoPreview = not self.engine.config.get("audio", "disable_preview") self.sortOrder = self.engine.config.get("game", "sort_order") self.tut = self.engine.world.tutorial self.playerList = self.players self.gameStarted = False self.gamePlayers = len(self.playerList) self.parts = [None for i in self.playerList] self.diffs = [None for i in self.playerList] self.time = 0 self.lastTime = 0 self.mode = 0 self.moreInfo = False self.moreInfoTime = 0 self.miniLobbyTime = 0 self.selected = 0 self.camera = Camera() self.cameraOffset = 0.0 self.song = None self.songLoader = None self.loaded = False text = _("Initializing Setlist...") if self.engine.cmdPlay == 2: text = _("Checking Command-Line Settings...") elif len(self.engine.world.songQueue) > 0: text = _("Checking Setlist Settings...") elif len(self.engine.world.songQueue) == 0: self.engine.world.playingQueue = False self.splash = Dialogs.showLoadingSplashScreen(self.engine, text) self.items = [] self.cmdPlay = False self.queued = True self.loadStartTime = time.time() if self.tut == True: self.library = self.engine.tutorialFolder else: self.library = os.path.join(self.engine.config.get("setlist", "base_library"), self.libraryName) if not os.path.isdir(self.engine.resource.fileName(self.library)): self.library = self.engine.resource.fileName( os.path.join(self.engine.config.get("setlist", "base_library"), Song.DEFAULT_LIBRARY) ) self.searchText = "" # user configurables and input management self.listingMode = 0 # with libraries or List All self.preloadSongLabels = False self.showCareerTiers = 1 + (self.careerMode and 1 or 0) # 0-Never; 1-Career Only; 2-Always self.scrolling = 0 self.scrollDelay = self.engine.config.get("game", "scroll_delay") self.scrollRate = self.engine.config.get("game", "scroll_rate") self.scrollTime = 0 self.scroller = [lambda: None, self.scrollUp, self.scrollDown] self.scoreDifficulty = Song.difficulties[self.engine.config.get("game", "songlist_difficulty")] self.scorePart = Song.parts[self.engine.config.get("game", "songlist_instrument")] self.sortOrder = self.engine.config.get("game", "sort_order") self.queueFormat = self.engine.config.get("game", "queue_format") self.queueOrder = self.engine.config.get("game", "queue_order") self.queueParts = self.engine.config.get("game", "queue_parts") self.queueDiffs = self.engine.config.get("game", "queue_diff") self.nilShowNextScore = self.engine.config.get("songlist", "nil_show_next_score") # theme information self.themename = self.engine.data.themeLabel self.theme = self.engine.data.theme # theme configurables self.setlistStyle = self.engine.theme.setlist.setlistStyle # 0 = Normal; 1 = List; 2 = Circular self.headerSkip = self.engine.theme.setlist.headerSkip # items taken up by header (non-static only) self.footerSkip = self.engine.theme.setlist.footerSkip # items taken up by footer (non-static only) self.itemSize = self.engine.theme.setlist.itemSize # delta (X, Y) (0..1) for each item (non-static only) self.labelType = self.engine.theme.setlist.labelType # Album covers (0) or CD labels (1) self.labelDistance = self.engine.theme.setlist.labelDistance # number of labels away to preload self.showMoreLabels = ( self.engine.theme.setlist.showMoreLabels ) # whether or not additional unselected labels are rendered on-screen self.texturedLabels = self.engine.theme.setlist.texturedLabels # render the art as a texture? self.itemsPerPage = self.engine.theme.setlist.itemsPerPage # number of items to show on screen self.followItemPos = (self.itemsPerPage + 1) / 2 self.showLockedSongs = self.engine.theme.setlist.showLockedSongs # whether or not to even show locked songs self.showSortTiers = ( self.engine.theme.setlist.showSortTiers ) # whether or not to show sorting tiers - career tiers take precedence. self.selectTiers = ( self.engine.theme.setlist.selectTiers ) # whether or not tiers should be selectable as a quick setlist. if self.engine.cmdPlay == 2: self.songName = Config.get("setlist", "selected_song") self.libraryName = Config.get("setlist", "selected_library") self.cmdPlay = self.checkCmdPlay() if self.cmdPlay: Dialogs.hideLoadingSplashScreen(self.engine, self.splash) return elif len(self.engine.world.songQueue) > 0: Dialogs.hideLoadingSplashScreen(self.engine, self.splash) return # variables for setlist management (Not that this is necessary here - just to see what exists.) self.songLoader = None # preview handling self.tiersPresent = False self.startingSelected = self.songName self.selectedIndex = 0 self.selectedItem = None self.selectedOffset = 0.0 self.previewDelay = 1000 self.previewLoaded = False self.itemRenderAngles = [0.0] self.itemLabels = [None] self.xPos = 0 self.yPos = 0 self.pos = 0 self.infoPage = 0 self.menu_force_reload = False self.menu_text_color = (1, 1, 1) self.menu_selected_color = (0.66, 0.66, 0) self.menu_text_pos = (0.2, 0.31) self.menu = Menu( self.engine, [ ConfigChoice(self.engine, self.engine.config, "game", "queue_format", autoApply=True), ConfigChoice(self.engine, self.engine.config, "game", "queue_order", autoApply=True), ConfigChoice(self.engine, self.engine.config, "game", "queue_parts", autoApply=True), ConfigChoice(self.engine, self.engine.config, "game", "queue_diff", autoApply=True), ActiveConfigChoice(self.engine, self.engine.config, "game", "sort_order", onChange=self.forceReload), ActiveConfigChoice( self.engine, self.engine.config, "game", "sort_direction", onChange=self.forceReload ), ActiveConfigChoice( self.engine, self.engine.config, "game", "songlist_instrument", onChange=self.forceReload ), ActiveConfigChoice( self.engine, self.engine.config, "game", "songlist_difficulty", onChange=self.forceReload ), ], name="setlist", fadeScreen=False, onClose=self.resetQueueVars, font=self.engine.data.pauseFont, pos=self.menu_text_pos, textColor=self.menu_text_color, selectedColor=self.menu_selected_color, ) # now, load the first library self.loadLibrary() # load the images self.loadImages()
def startGame(self, fromQueue=False): # note this is not refined. if len(self.engine.world.songQueue) == 0: return showDialog = True if not fromQueue and self.queueFormat == 1 and len(self.engine.world.songQueue) > 1: self.engine.world.songQueue.setFullQueue() self.engine.world.playingQueue = True if self.queueOrder == 1: self.songName, self.libraryName = self.engine.world.songQueue.getRandomSong() else: self.songName, self.libraryName = self.engine.world.songQueue.getSong() info = Song.loadSongInfo(self.engine, self.songName, library=self.libraryName) guitars = [] drums = [] vocals = [] for part in info.parts: if part.id == 4 or part.id == 7: drums.append(part) elif part.id == 5: vocals.append(part) else: guitars.append(part) choose = [[] for i in self.players] for i, player in enumerate(self.players): j = self.engine.world.songQueue.getParts()[i] if player.controlType == 2 or player.controlType == 3: choose[i] = drums elif player.controlType == 5: choose[i] = vocals else: choose[i] = guitars if self.queued: showDialog = False for i, player in enumerate(self.players): if Song.parts[j] in choose[i]: p = Song.parts[j] elif self.queueParts == 0: if j == 0: for k in [3, 1, 2]: if Song.parts[k] in choose[i]: p = Song.parts[k] break elif j == 1: for k in [2, 0, 3]: if Song.parts[k] in choose[i]: p = Song.parts[k] break elif j == 2: for k in [1, 0, 3]: if Song.parts[k] in choose[i]: p = Song.parts[k] break elif j == 3: for k in [0, 1, 2]: if Song.parts[k] in choose[i]: p = Song.parts[k] break j = self.engine.world.songQueue.getDiffs()[i] if Song.difficulties[j] in info.partDifficulties[p.id]: d = Song.difficulties[j] elif self.queueDiffs == 0: if j == 0: for k in range(1, 4): if Song.difficulties[k] in info.partDifficulties[p.id]: d = Song.difficulties[k] elif j == 1: for k in range(2, 5): if Song.difficulties[k % 4] in info.partDifficulties[p.id]: d = Song.difficulties[k % 4] elif j == 2: if Song.difficulties[3] in info.partDifficulties[p.id]: d = Song.difficulties[3] else: for k in range(1, -1, -1): if Song.difficulties[k] in info.partDifficulties[p.id]: d = Song.difficulties[k] else: for k in range(2, -1, -1): if Song.difficulties[k] in info.partDifficulties[p.id]: d = Song.difficulties[k] elif self.queueDiffs == 1: if j == 3: for k in range(2, -1, -1): if Song.difficulties[k] in info.partDifficulties[p.id]: d = Song.difficulties[k] elif j == 2: for k in range(1, -2, -1): if Song.difficulties[k % 4] in info.partDifficulties[p.id]: d = Song.difficulties[k % 4] elif j == 1: if Song.difficulties[0] in info.partDifficulties[p.id]: d = Song.difficulties[0] else: for k in range(2, 4): if Song.difficulties[k] in info.partDifficulties[p.id]: d = Song.difficulties[k] else: for k in range(1, 4): if Song.difficulties[k] in info.partDifficulties[p.id]: d = Song.difficulties[k] if p and d: player.part = p player.difficulty = d else: showDialog = True if showDialog: ready = False while not ready: ready = Dialogs.choosePartDiffs(self.engine, choose, info, self.players) if not ready and not self.queued and not self.engine.cmdPlay: return False if self.engine.cmdPlay > 0: self.engine.cmdPlay = 3 self.freeResources() self.engine.world.createScene("GuitarScene", libraryName=self.libraryName, songName=self.songName) self.gameStarted = True
def run(self, ticks): SceneClient.run(self, ticks) players = 1 if not self.wizardStarted: self.wizardStarted = True if self.engine.cmdPlay == 1: self.songName = Config.get("game", "selected_song") self.libraryName = Config.get("game", "selected_library") self.engine.cmdPlay = 2 if not self.songName: while True: self.libraryName, self.songName = \ Dialogs.chooseSong(self.engine, \ selectedLibrary = Config.get("game", "selected_library"), selectedSong = Config.get("game", "selected_song")) if self.libraryName == None: newPath = Dialogs.chooseFile(self.engine, masks = ["*/songs"], prompt = _("Choose a new songs directory."), dirSelect = True) if newPath != None: Config.set("game", "base_library", os.path.dirname(newPath)) Config.set("game", "selected_library", "songs") Config.set("game", "selected_song", "") self.engine.resource.refreshBaseLib() #myfingershurt - to let user continue with new songpath without restart if not self.songName: self.session.world.finishGame() return Config.set("game", "selected_library", self.libraryName) Config.set("game", "selected_song", self.songName) info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) selected = False escape = False escaped = False #while True: #this nesting is now useless #MFH - add "Practice" mode, which will activate a section selection menu before "part" #racer: main menu instead of second menu practice #self.player.practiceMode = Player.PracticeSet #MFH - parameters for newLocalGame: #players = -1 (party mode), 1, 2 #mode1p = 0 (quickplay), 1 (practice), 2 (career) #mode2p = 0 (face-off), 1 (pro face-off) #Config.define("game", "players", int, 1) #Config.define("player0","mode_1p", int, 0) #Config.define("player1","mode_2p", int, 0) if Config.get("player0","mode_1p") == 1 and Config.get("game","players") == 1: #practice mode self.player.practiceMode = True else: self.player.practiceMode = False while True: #new nesting for Practice Mode - section / start time selection if self.player.practiceMode: #self.engine.resource.load(self, "song", lambda: Song.loadSong(self.engine, songName, library = self.libraryName, notesOnly = True, part = [player.part for player in self.playerList]), onLoad = self.songLoaded) #startTime = Dialogs.chooseItem(self.engine, info.sections, "%s \n %s" % (info.name, _("Start Section:"))) sectionLabels = [sLabel for sLabel,sPos in info.sections] startLabel = Dialogs.chooseItem(self.engine, sectionLabels, "%s \n %s" % (info.name, _("Start Section:"))) if startLabel: Log.debug("Practice start section selected: " + startLabel) else: startLabel = "Gig" if startLabel: self.player.practiceSection = startLabel #find start position in array: self.player.startPos = [sPos for sLabel,sPos in info.sections if sLabel == startLabel] Log.debug("Practice start position retrieved: " + str(self.player.startPos) ) else: break; #if not self.player.practiceMode: #selected = True #this causes "gig" mode to start song with all defaults #escape = True #this causes "gig" mode to exit out to the song selection #escaped = True #this does nothing :( #break; while True: #new nesting for Practice Mode selection if len(info.parts) > 1: p = Dialogs.chooseItem(self.engine, info.parts, "%s \n %s" % (info.name, _("Player 1 Choose a part:")), selected = self.player.part) else: p = info.parts[0] if p: self.player.part = p else: if not self.player.practiceMode: escaped = True break; while True: if len(info.difficulties) > 1: d = Dialogs.chooseItem(self.engine, info.difficulties, "%s \n %s" % (info.name, _("Player 1 Choose a difficulty:")), selected = self.player.difficulty) else: d = info.difficulties[0] if d: self.player.difficulty = d else: if len(info.parts) <= 1: #escape = True escaped = True break while True: if self.engine.config.get("game", "players") > 1: #p = Dialogs.chooseItem(self.engine, info.parts + ["Party Mode"] + ["No Player 2"], "%s \n %s" % (info.name, _("Player 2 Choose a part:")), selected = self.player2.part) p = Dialogs.chooseItem(self.engine, info.parts, "%s \n %s" % (info.name, _("Player 2 Choose a part:")), selected = self.player2.part) #if p and p == "No Player 2": # players = 1 # selected = True # self.player2.part = p # break #elif p and p == "Party Mode": # players = -1 # selected = True # self.player2.part = p # break #elif p and p != "No Player 2" and p != "Party Mode": if p: players = 2 self.player2.part = p else: if len(info.difficulties) <= 1: escaped = True if len(info.parts) <= 1: escape = True break while True: if len(info.difficulties) > 1: d = Dialogs.chooseItem(self.engine, info.difficulties, "%s \n %s" % (info.name, _("Player 2 Choose a difficulty:")), selected = self.player2.difficulty) else: d = info.difficulties[0] if d: self.player2.difficulty = d else: break selected = True break else: selected = True break if selected: break if selected or escaped: break #if selected or escaped: #new nesting for Practice Mode selection if selected or escaped: #new nesting for Practice Mode selection break if selected or escaped: #new nesting for Practice Mode section selection break #useless practice mode nesting #if selected or escape: # break if (not selected) or escape: continue break else: #evilynux - Fixes Practice Mode from the cmdline if Config.get("player0","mode_1p") == 1 and Config.get("game","players") == 1: self.player.practiceMode = True info = Song.loadSongInfo(self.engine, self.songName, library = self.libraryName) if self.engine.cmdPlay == 2: if len(info.difficulties) >= self.engine.cmdDiff: self.player.difficulty = info.difficulties[self.engine.cmdDiff] if len(info.parts) >= self.engine.cmdPart: self.player.part = info.parts[self.engine.cmdPart] # Make sure the difficulty we chose is available if not self.player.difficulty in info.difficulties: self.player.difficulty = info.difficulties[0] if not self.player.part in info.parts: self.player.part = info.parts[0] if not self.player.difficulty in info.difficulties: self.player.difficulty = info.difficulties[0] if not self.player.part in info.parts: self.player.part = info.parts[0] self.session.world.deleteScene(self) self.session.world.createScene("GuitarScene", libraryName = self.libraryName, songName = self.songName, Players = players)