def btn_setstyle(params): context.chat_data['style'] = int(params) stylename = Lang.get("keyboard.setstyle.random", lang) if int(params) < 0 else Styles.get( int(params)).get_name(lang) update.callback_query.message.reply_text( Lang.get('command.setstyle.changed', lang, style=stylename))
def readLangs(lang1, lang2, valid=False, reverse=False): print("Reading lines...") if not valid: with open("data/train.%s" % lang1, "r", encoding="utf-8") as f: lines1 = f.readlines() with open("data/train.%s" % lang2, "r", encoding="utf-8") as f: lines2 = f.readlines() else: with open("data/val.%s" % lang1, "r", encoding="utf-8") as f: lines1 = f.readlines() with open("data/val.%s" % lang2, "r", encoding="utf-8") as f: lines2 = f.readlines() print("Normaraize...") for i, line in enumerate(my_tqdm(lines1)): lines1[i] = normalizeString(line) for i, line in enumerate(my_tqdm(lines2)): lines2[i] = line.replace('\n', '') if reverse: pairs = list(zip(lines2, lines1)) source_lang = Lang(lang2) target_lang = Lang(lang1) else: pairs = list(zip(lines1, lines2)) source_lang = Lang(lang1) target_lang = Lang(lang2) return source_lang, target_lang, pairs
def btn_setlang(params): context.chat_data['lang'] = params update.callback_query.message.reply_text( Lang.get('command.setlang.changed', params, lang=Lang.get_lang(params, True))) btn_achlang(params, True)
def set_locale(self, locale): self.locale = Lang.check_locale(locale) if self.locale is None: self.locale = Lang.find_substitute(locale) print( "**WARNING: bad locale type %s passed to CommandLinePlayer. Reverting to %s" % (locale, self.locale)) return self.locale
def set_locale(self, locale): self.locale = Lang.check_locale(locale) if self.locale is None: self.locale = Lang.guess_locale() print( "**WARNING: bad locale type %s passed to MusicSheetMaker. Reverting to %s" % (locale, self.locale)) return self.locale
def readLangs(): print("reading languages...") lines = open("data/eng-fra.txt", encoding='utf-8').read().strip().split('\n') pairs = [[normalizeString(s) for s in l.split('\t')] for l in lines] input_lang = Lang.Lang("eng") output_lang = Lang.Lang("fra") return input_lang, output_lang, pairs
def achlang(update: Update, context: CallbackContext) -> None: keyboard = [] for lang in Styles.get(context.chat_data.get('style')).get_langs(): keyboard.append([ InlineKeyboardButton(Lang.get_lang(lang), callback_data=f"achlang.{lang}") ]) reply_markup = InlineKeyboardMarkup(keyboard) update.message.reply_text(Lang.get('command.achlang.select', context.chat_data.get('lang')), reply_markup=reply_markup)
def set_locale(self, locale): self.locale = Lang.check_locale(locale) if self.locale is None: try: self.locale = Lang.check_locale(self.owner.get_locale()) except: pass if self.locale is None: self.locale = Lang.guess_locale() print("**WARNING: bad locale type %s passed to Communicator. Reverting to %s"%(locale, self.locale)) return self.locale
def setstyle(update: Update, context: CallbackContext) -> None: lang = context.chat_data.get('lang') keyboard = [] for i, st in enumerate(Styles.styles): keyboard.append([ InlineKeyboardButton(st.get_name(), callback_data=f"setstyle.{i}") ]) keyboard.append([ InlineKeyboardButton(Lang.get('keyboard.setstyle.random', lang), callback_data=f"setstyle.-1") ]) reply_markup = InlineKeyboardMarkup(keyboard) update.message.reply_text(Lang.get('command.setstyle.select', lang), reply_markup=reply_markup)
def start(update: Update, context: CallbackContext) -> None: if context.user_data.get('new', True): context.bot_data['users_c'] = context.bot_data.get('users_c', 0) + 1 logger.info(f"New user! {update.effective_user.name}") context.user_data['new'] = False update.message.reply_text( Lang.get('command.start', context.chat_data.get('lang')))
def create_achievement(update: Update, context: CallbackContext) -> None: lang = context.chat_data.get('lang') # Checking name & description vals = Achievement.parse_message(update.message.text or update.message.caption) for err in Achievement.check_values(**vals): update.message.reply_text(Lang.get(err, lang, **Achievement.LIMITS)) vals = None if not vals: return # Icon & style image = None if update.message.photo: photos = update.message.photo image = photos[1 if len(photos) > 1 else 0].get_file().file_path elif context.chat_data.get('image_url'): image = context.chat_data.get('image_url') context.chat_data['image_url'] = None vals['icon'] = Tools.download_image(image or Tools.search_image(vals['name'])) vals['style'] = Styles.get(context.chat_data.get('style')) # Setting language ach_lang = context.chat_data.get('ach_lang', 'ENG') if vals['style'].change_lang(ach_lang) != 'ok': update.message.reply_text( Lang.get('error.achievement.no_lang', lang, lang=ach_lang, style=vals['style'].get_name(lang))) ach = Achievement(**vals) gen = ach.generate() if type(gen) is str: update.message.reply_text(Lang.get(gen, lang)) else: update.message.reply_photo(gen) # Incrementing stats context.bot_data['ach_generated'] = context.bot_data.get( 'ach_generated', 0) + 1 context.chat_data['ach_generated'] = context.chat_data.get( 'ach_generated', 0) + 1
def stats(update: Update, context: CallbackContext) -> None: keys = { 'ach_global': context.bot_data.get('ach_generated', 0), 'ach_chat': context.chat_data.get('ach_generated', 0), 'users_count': context.bot_data.get('users_c', 0), 'user_styles': '0 (coming soon)' } update.message.reply_text( Lang.get('command.stats.achievement', context.chat_data.get('lang'), **keys))
def readLangs(self, lang1, lang2, reverse=False): print("Reading lines...") lines = open('../../Data/Zulu/zulu.clean.train.conll', encoding='utf-8').\ read().strip().split('\n') data = [] for line in lines: line = line.split(" | ") ortho = self.removeTags(line[2]) data.append(line[0] + "\t" + ortho) pairs = [[self.normalizeString(s) for s in l.split('\t')] for l in data] if reverse: pairs = [list(reversed(p)) for p in pairs] input_lang = Lang.Lang(lang2) output_lang = Lang.Lang(lang1) else: input_lang = Lang.Lang(lang1) output_lang = Lang.Lang(lang2) return input_lang, output_lang, pairs
def __init__(self, identifier, title=None, abstract=None, metadata=[], profile=[], version="None", statusSupported=True, storeSupported=False, grassLocation=None, logFile=sys.stderr): """Contructor""" self.identifier = identifier self.version = version self.metadata = metadata self.title = title self.abstract = abstract self.wsdl = None self.profile = profile # "true" or "True" -> True if type(storeSupported) == type(""): if storeSupported.find("t") == 0 or\ storeSupported.find("T") == 0: storeSupported = True else: storeSupported = False self.storeSupported = storeSupported if type(statusSupported) == type(""): if statusSupported.find("t") == 0 or\ statusSupported.find("T") == 0: statusSupported = True else: statusSupported = False self.statusSupported = statusSupported # status not supported on windows if os.name == "nt": self.statusSupported = False self.debug = False self.status = Status() self.inputs = {} self.orderedInputs = [] self.outputs = {} self.lang = Lang.Lang() self.grassLocation = grassLocation
def __init__(self, maker): self.input_mode = None self.note_parser = None self.icon_delimiter = ' ' self.pause = '.' self.quaver_delimiter = '-' self.comment_delimiter = '#' self.repeat_indicator = '*' self.maker = maker self.directory_base = self.maker.get_directory_base() try: self.locale = self.maker.get_locale() except AttributeError: # Should never happen self.locale = Lang.guess_locale() print( '**WARNING: SongParser self.maker has no locale. Reverting to %s' % self.locale)
def sys_stats(update: Update, context: CallbackContext) -> None: def get_uptime() -> dict: delta = int(time.time()) - START_TIME return { 'ut_d': str(delta // 86400), 'ut_h': str(delta // 3600 % 60), 'ut_m': str(delta // 60 % 60) } mem = psutil.Process(getpid()).memory_info() keys = { **get_uptime(), # ut_d, ut_h, ut_m 'ram_p': "{0:.2f}".format(mem.rss / mem.vms * 100), 'ram_mb': str(mem.rss // (1024**2)) } update.message.reply_text( Lang.get('command.stats.sys', context.chat_data.get('lang'), **keys))
def params_command(update: Update, context: CallbackContext) -> None: update.message.reply_text( Lang.get('command.null', context.chat_data.get('lang')))
def get_short_desc(self, locale='en_US'): return Lang.get_string(self.short_desc_yaml, locale)
def btn_achlang(params, same_lang=False): context.chat_data['ach_lang'] = params update.callback_query.message.reply_text( Lang.get('command.achlang.changed', params if same_lang else lang, lang=Lang.get_lang(params, True)))
self.bar.update(idx + 1) line = line.lower() if self.lowercase else line yield self.l_en.tokenize_sent(line) if self.model is not None: if self.epoch_number != self.n_epochs: SAVE_FILE_NAME = self.model_prefix + '_iter_' + str( self.epoch_number) + '.model' else: # Last Epoch SAVE_FILE_NAME = self.model_prefix + '.model' self.model.save(SAVE_FILE_NAME) ROOT_DIR = "" if __name__ == "__main__": l_en = Ln.Lang('en') VOCAB_FILE = ROOT_DIR + 'data/vocab.pkl' l_en.load_file(VOCAB_FILE) data_file = ROOT_DIR + 'data/tinyTrain.txt' model_prefix = ROOT_DIR + 'gensim_models/model_all_lowercase_' data = [] print 'LOADING DATA...' sys.stdout.flush() with io.open(data_file, encoding='utf-8', mode='r', errors='replace') as f: for line in f: line = line.strip().split('\t') data.append(line[0]) data.append(line[1]) print 'LOADING DONE ...' sys.stdout.flush()
def require_name(update: Update, context: CallbackContext) -> None: photos = update.message.photo context.chat_data['image_url'] = photos[ 1 if len(photos) > 1 else 0].get_file().file_path update.message.reply_text( Lang.get("achievement.require_name", context.chat_data.get('lang')))
def __init__(self, owner, locale): self.owner = owner self.memory = QueryMemory(self.owner) self.name = self.owner.get_name() self.locale=self.set_locale(locale) # A dictionary of standard queries arguments # The key must be lower case without blanks, use _ instead # TODO: create generic (quasi-empty) stock queries, such as Information to output dome text self.query_stock = { # Queries asked by the Player / Music Cog 'create_song': {'class': QueryOpen.__name__, 'handler': 'create_song', # The name of the method that must be executed by the recipient 'question': 'create_song', 'reply_type': ReplyType.BUFFERS }, # Generic Query 'information': {'class': Information.__name__, 'handler': 'None', 'question': '', 'reply_type': ReplyType.TEXT }, 'instructions_stdout': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/instructions_stdout/foreword", self.locale), 'question': Lang.get_string("stock_queries/instructions_stdout/question", self.locale), 'afterword': Lang.get_string("stock_queries/instructions_stdout/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/instructions_stdout/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/instructions_stdout/help_text", self.locale) }, 'instructions_website': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/instructions_website/foreword", self.locale), 'question': Lang.get_string("stock_queries/instructions_website/question", self.locale), 'afterword': Lang.get_string("stock_queries/instructions_website/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/instructions_website/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/instructions_website/help_text", self.locale) }, 'instructions_botcog': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/instructions_botcog/foreword", self.locale), 'question': Lang.get_string("stock_queries/instructions_botcog/question", self.locale), 'afterword': Lang.get_string("stock_queries/instructions_botcog/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/instructions_botcog/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/instructions_botcog/help_text", self.locale) }, 'render_modes': {'class': QueryMultipleChoices.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/render_modes/foreword", self.locale), 'question': Lang.get_string("stock_queries/render_modes/question", self.locale), 'afterword': Lang.get_string("stock_queries/render_modes/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/render_modes/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/render_modes/help_text", self.locale), 'reply_type': ReplyType.RENDERMODES, 'limits': [] }, 'song_title': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/song_title/foreword", self.locale), 'question': Lang.get_string("stock_queries/song_title/question", self.locale), 'afterword': Lang.get_string("stock_queries/song_title/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/song_title/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/song_title/help_text", self.locale), 'reply_type': ReplyType.TEXT, 'limits': None }, 'original_artist': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/original_artist/foreword", self.locale), 'question': Lang.get_string("stock_queries/original_artist/question", self.locale), 'afterword': Lang.get_string("stock_queries/original_artist/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/original_artist/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/original_artist/help_text", self.locale), 'reply_type': ReplyType.TEXT, 'limits': None }, 'transcript_writer': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/transcript_writer/foreword", self.locale), 'question': Lang.get_string("stock_queries/transcript_writer/question", self.locale), 'afterword': Lang.get_string("stock_queries/transcript_writer/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/transcript_writer/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/transcript_writer/help_text", self.locale), 'reply_type': ReplyType.TEXT, 'limits': None }, 'notes_file': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/notes_file/foreword", self.locale), 'question': Lang.get_string("stock_queries/notes_file/question", self.locale), 'afterword': Lang.get_string("stock_queries/notes_file/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/notes_file/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/notes_file/help_text", self.locale), 'reply_type': ReplyType.OTHER, 'limits': None }, 'file': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/file/foreword", self.locale), 'question': Lang.get_string("stock_queries/file/question", self.locale), 'afterword': Lang.get_string("stock_queries/file/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/file/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/file/help_text", self.locale), 'reply_type': ReplyType.FILEPATH, 'limits': '.' }, 'notes': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/notes/foreword", self.locale), 'question': Lang.get_string("stock_queries/notes/question", self.locale), 'afterword': Lang.get_string("stock_queries/notes/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/notes/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/notes/help_text", self.locale), 'reply_type': ReplyType.TEXT, 'limits': None }, 'one_input_mode': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/one_input_mode/foreword", self.locale), 'question': Lang.get_string("stock_queries/one_input_mode/question", self.locale), 'afterword': Lang.get_string("stock_queries/one_input_mode/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/one_input_mode/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/one_input_mode/help_text", self.locale) }, 'musical_notation': {'class': QueryChoice.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/musical_notation/foreword", self.locale), 'question': Lang.get_string("stock_queries/musical_notation/question", self.locale), 'afterword': Lang.get_string("stock_queries/musical_notation/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/musical_notation/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/musical_notation/help_text", self.locale), 'reply_type': ReplyType.INPUTMODE, 'limits': [] }, 'no_possible_key': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/no_possible_key/foreword", self.locale), 'question': Lang.get_string("stock_queries/no_possible_key/question", self.locale), 'afterword': Lang.get_string("stock_queries/no_possible_key/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/no_possible_key/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/no_possible_key/help_text", self.locale) }, 'one_possible_key': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/one_possible_key/foreword", self.locale), 'question': Lang.get_string("stock_queries/one_possible_key/question", self.locale), 'afterword': Lang.get_string("stock_queries/one_possible_key/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/one_possible_key/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/one_possible_key/help_text", self.locale) }, 'possible_keys': {'class': QueryChoice.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/possible_keys/foreword", self.locale), 'question': Lang.get_string("stock_queries/possible_keys/question", self.locale), 'afterword': Lang.get_string("stock_queries/possible_keys/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/possible_keys/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/possible_keys/help_text", self.locale), 'reply_type': ReplyType.NOTE, 'limits': [] }, 'recommended_key': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/recommended_key/foreword", self.locale), 'question': Lang.get_string("stock_queries/recommended_key/question", self.locale), 'afterword': Lang.get_string("stock_queries/recommended_key/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/recommended_key/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/recommended_key/help_text", self.locale), 'reply_type': ReplyType.NOTE, 'limits': None }, 'octave_shift': {'class': QueryOpen.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/octave_shift/foreword", self.locale), 'question': Lang.get_string("stock_queries/octave_shift/question", self.locale), 'afterword': Lang.get_string("stock_queries/octave_shift/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/octave_shift/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/octave_shift/help_text", self.locale), 'reply_type': ReplyType.INTEGER, 'limits': [-6, 6] }, 'one_song_file': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/one_song_file/foreword", self.locale), 'question': Lang.get_string("stock_queries/one_song_file/question", self.locale), 'afterword': Lang.get_string("stock_queries/one_song_file/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/one_song_file/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/one_song_file/help_text", self.locale) }, 'several_song_files': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/several_song_files/foreword", self.locale), 'question': Lang.get_string("stock_queries/several_song_files/question", self.locale), 'afterword': Lang.get_string("stock_queries/several_song_files/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/several_song_files/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/several_song_files/help_text", self.locale) }, 'no_song_file': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/no_song_file/foreword", self.locale), 'question': Lang.get_string("stock_queries/no_song_file/question", self.locale), 'afterword': Lang.get_string("stock_queries/no_song_file/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/no_song_file/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/no_song_file/help_text", self.locale) }, 'few_errors': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/few_errors/foreword", self.locale), 'question': Lang.get_string("stock_queries/few_errors/question", self.locale), 'afterword': Lang.get_string("stock_queries/few_errors/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/few_errors/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/few_errors/help_text", self.locale) }, 'many_errors': {'class': Information.__name__, 'handler': 'None', 'foreword': Lang.get_string("stock_queries/many_errors/foreword", self.locale), 'question': Lang.get_string("stock_queries/many_errors/question", self.locale), 'afterword': Lang.get_string("stock_queries/many_errors/afterword", self.locale), 'input_tip': Lang.get_string("stock_queries/many_errors/input_tip", self.locale), 'help_text': Lang.get_string("stock_queries/many_errors/help_text", self.locale) }, }
def get_long_desc(self, locale='en_US'): return Lang.get_string(self.long_desc_yaml, locale)
options['SAVE_PREFIX'] += '_LR_%.4f' % (options['LR']) options['SAVE_PREFIX'] += '_LAST_NON_LINEAR_%s' % (str( options['LAST_NON_LINEAR'])) options['TRAIN_FLAG'] = args.train_flag if hasattr(args, 'train_flag') else True options['CONTINUE_TRAINING'] = args.continue_training if hasattr( args, 'continue_training') else True return options args = get_arguments() options = get_options(args) l_en = L.Lang('en') l_en.load_file(options['VOCAB']) def data_generator(filename, l_en): X = [] y = [] valid_labels = set(['neutral', 'contradiction', 'entailment']) unknown_count = 0 with open(filename) as f: for line in f: line = line.strip().split('\t') if line[2] == '-': unknown_count += 1 continue assert line[2] in valid_labels, "Unknown label %s" % (line[2])
def __init__(self, maker, music_key='C'): if isinstance(music_key, str): self.music_key = music_key else: print('\n***Warning: Invalid song key: using C instead\n') self.music_key = 'C' self.maker = maker try: self.locale = self.maker.get_locale() except AttributeError: #Should never happen self.locale = Lang.guess_locale() print( '**WARNING: Song self.maker has no locale. Reverting to: %s' % self.locale) self.directory_base = self.maker.get_directory_base() self.directory_fonts = os.path.normpath( os.path.join(self.directory_base, 'fonts')) self.lines = [] self.meta = { 'title': [ Lang.get_string("song_meta/title", self.locale) + ':', Lang.get_string("song_meta/untitled", self.locale) ], 'artist': [Lang.get_string("song_meta/artist", self.locale) + ':', ''], 'transcript': [Lang.get_string("song_meta/transcript", self.locale) + ':', ''], 'song_key': [Lang.get_string("song_meta/musical_key", self.locale) + ':', ''] } #self.title = self.meta['title'][1] self.maxIconsPerLine = 10 self.maxLinesPerFile = 10 self.maxFiles = 10 self.harp_AspectRatio = 1.455 self.harp_relspacings = ( 0.13, 0.1 ) # Fraction of the harp width that will be allocated to the spacing between harps self.HTML_note_width = '1em' self.SVG_viewPort = (0.0, 0.0, 1334.0, 750.0) minDim = self.SVG_viewPort[2] * 0.01 self.SVG_viewPortMargins = (13.0, 7.5) self.pt2px = 96.0 / 72 self.fontpt = 12 self.SVG_text_height = self.fontpt * self.pt2px # In principle this should be in em self.SVG_line_width = self.SVG_viewPort[2] - self.SVG_viewPortMargins[0] SVG_harp_width = max( minDim, (self.SVG_viewPort[2] - self.SVG_viewPortMargins[0]) / (1.0 * self.maxIconsPerLine * (1 + self.harp_relspacings[0]))) self.SVG_harp_size = (SVG_harp_width, max(minDim, SVG_harp_width / self.harp_AspectRatio)) self.SVG_harp_spacings = (self.harp_relspacings[0] * SVG_harp_width, self.harp_relspacings[1] * SVG_harp_width / self.harp_AspectRatio) if not no_PIL_module: self.png_size = (1334 * 2, 750 * 2) # must be an integer tuple self.png_margins = (13, 7) self.png_harp_size0 = instruments.Harp( self.get_maker()).render_in_png().size # A tuple self.png_harp_spacings0 = (int(self.harp_relspacings[0] * self.png_harp_size0[0]), int(self.harp_relspacings[1] * self.png_harp_size0[1])) self.png_harp_size = None self.png_harp_spacings = None self.png_line_width = int( self.png_size[0] - self.png_margins[0] ) # self.png_lyric_relheight = instruments.Voice().lyric_relheight self.png_lyric_size0 = (self.png_harp_size0[0], instruments.Voice( self.get_maker()).get_lyric_height()) self.png_lyric_size = None self.png_dpi = (96 * 2, 96 * 2) self.png_compress = 6 self.font_color = (0, 0, 0) self.png_color = (255, 255, 255) # self.font_color = (0, 0, 0) #Discord colors # self.png_color = (54, 57, 63) #Discord colors self.png_font_size = 36 self.png_title_font_size = 48 self.png_font = os.path.normpath( os.path.join(self.directory_fonts, 'NotoSansCJKjp-Regular.otf')) if not no_mido_module: # WARNING: instrument codes correspond to General Midi codes (see Wikipedia) minus 1 # Instrument will sound very strange if played outside its natural pitch range midi_instruments = { 'piano': 0, 'guitar': 24, 'flute': 73, 'pan': 75 } self.midi_note_duration = 0.3 # note duration is seconds for 120 bpm self.midi_bpm = 120 # Beats per minute self.midi_instrument = midi_instruments['piano'] try: self.midi_key = re.sub( r'#', '#m', self.music_key) # For mido sharped keys are minor except: print( '\n***Warning: Invalid music key passed to the MIDI renderer: using C instead\n' ) self.midi_key = 'C'
reply_valid = True #to be sure to break the loop if q.get_expect_reply(): #print('%%%DEBUG. PLAYER, YOU ARE BEING PROMPTED%%%') #FIXME: for debugging only answer = input('%s: ' % question) q.reply_to(answer) reply_valid = q.get_reply_validity() else: #print('%%%DEBUG. PLAYER, YOU ARE BEING TOLD%%%') #FIXME: for debugging only print(question) q.reply_to('ok') reply_valid = q.get_reply_validity() try: player = CommandLinePlayer(locale=Lang.guess_locale()) maker = MusicSheetMaker(locale=Lang.guess_locale()) q = player.communicator.send_stock_query('create_song', recipient=maker) maker.execute_queries(q) except QueriesExecutionAbort as qExecAbort: print(repr(qExecAbort)) ''' # for debugging only print('\n%%%DEBUG. MAIN script has ended%%%') print('\n\n%%%DEBUG. Player memory:') player.communicator.memory.print_out() print('\n%%%DEBUG. Maker memory:')