How to display musical notation using music21 in ipython/python with MuseScore WITHOUT MuseScore re-opening every time .show() is called? - ipython

I am using music21 with MuseScore in an ipython notebook. It works well, the only problem is that every time I create a Stream and then run my_stream.show(), it takes a forever because it waits to open the MuseScore application. This happens even if MuseScore is already open (it opens a second copy of the app, which then closes itself after the image is printed).
How can I prevent music21 from re-opening MuseScore each time and get it to use the already opened app instead?
EDIT: Adding version/OS info
I'm on a mac (OSX 10.10.4) using MuseScore version 2.1.0
I've also tried the method outlined here to print out sheet music in an ipython notebook but the same thing happened.
For the second method at least, the problem seems to be in music21/converter/subConverter.py.
Under
class ConverterMusicXML(SubConverter):
There's this section:
musescoreRun = '"' + musescorePath + '" ' + fp + " -o " + fpOut + " -T 0 "
if 'dpi' in keywords:
musescoreRun += " -r " + str(keywords['dpi'])
if common.runningUnderIPython():
musescoreRun += " -r " + str(defaults.ipythonImageDpi)
storedStrErr = sys.stderr
fileLikeOpen = six.StringIO()
sys.stderr = fileLikeOpen
os.system(musescoreRun)
fileLikeOpen.close()
sys.stderr = storedStrErr
I believe that this line in particular
os.system(musescoreRun)
is opening MuseScore independently each time, but I can't figure out what to replace it with that will allow music21 to find the already running instance of MuseScore.

Same problem errors. Here refers an issue on GitHub:
... changing os.system(musescoreRun) line 891 of subconverters.py by subprocess.run(musescoreRun). You need also to import subprocess at the start of subconverters.py.
Maybe it works for you!

Related

Python 3.8.1 subprocess call/Popen methods not working

I recently updated my python package from 3.6.8 to 3.8.10 , from what I've read there is no much difference between the versions.
But I've encountered some problems in my code speficially with the subprocess.Popen() method not working as expected.
commands = ["sc start " + service_name_string]
command_executions =
subprocess.Popen('cmd.exe', shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for cmd in commands:
command_executions.stdin.write(str(cmd + "\n").encode())
time.sleep(1)
command_executions.stdin.close()
another option
or another example is running the following command :
uninstall_process = subprocess.call(uninstall_string,shell=True)
this really puzzling me because there is no problem or exception (i did not inlcude the exception wrapping)

ng server command opens file open option menu

In VS code editor, ng serve command opening "How do you want to open this file?" dialog box in
The answer by Petr Freiberg helped get me to what I believe is a better solution. Instead of deleting files that may or may not actually be important for the system, we should update our PATH variables so that the "correct" command is found first.
In my situation, I had my npm paths in this order:
C:\Users\Me\AppData\Roaming\npm\node_modules\#angular\cli\bin
C:\Users\Me\AppData\Roaming\npm
I just switched the order so that C:\Users\Me\AppData\Roaming\npm came first.
The issue is that the terminal is finding the first "command match" which may just be a file, so that is why it is asking where you want to open it.
I did run the command Run Get-Command -All ng | ForEach-Object Path as Petr suggested, which called out the order issue I describe here.
I encountered a similar problem when executing a Docker command within Visual Studio Code. I also got a window asking "How do you want to open this file?". I think the problem is not in Visual Studio Code, but in PowerShell, which Visual Studio Code uses.
I solved it like this:
Run Get-Command -All docker | ForEach-Object Path
Among the file paths returned, remove those that do not end in *.exe (use
Remove-Item):
For ng it should be same.
Credits: https://stackoverflow.com/a/63981418/1816014
i have faced the same issue, while trying to run ng -v or ng --version, it pops open a Open option editor, which gives following ng.js text...
#!/usr/bin/env node
'use strict';
// Provide a title to the process in `ps`.
// Due to an obscure Mac bug, do not start this title with any symbol.
try {
process.title = 'ng ' + Array.from(process.argv).slice(2).join(' ');
} catch (_) {
// If an error happened above, use the most basic title.
process.title = 'ng';
}
// This node version check ensures that extremely old versions of node are not used.
// These may not support ES2015 features such as const/let/async/await/etc.
// These would then crash with a hard to diagnose error message.
// tslint:disable-next-line: no-var-keyword
var version = process.versions.node.split('.').map((part) => Number(part));
if (version[0] % 2 === 1 && version[0] > 14) {
// Allow new odd numbered releases with a warning (currently v15+)
console.warn(
'Node.js version ' +
process.version +
' detected.\n' +
'Odd numbered Node.js versions will not enter LTS status and should not be used for production.' +
' For more information, please see https://nodejs.org/en/about/releases/.',
);
require('../lib/init');
} else if (
version[0] < 12 ||
version[0] === 13 ||
(version[0] === 12 && version[1] < 14) ||
(version[0] === 14 && version[1] < 15)
) {
// Error and exit if less than 12.14 or 13.x or less than 14.15
console.error(
'Node.js version ' +
process.version +
' detected.\n' +
'The Angular CLI requires a minimum Node.js version of either v12.14 or v14.15.\n\n' +
'Please update your Node.js version or visit https://nodejs.org/ for additional instructions.\n',
);
process.exitCode = 3;
} else {
require('../lib/init');
}
what is the error here, i tried uninstall clear cache and install but still same error....

Vim extension coc producing errors after fresh install?

I installed the latest branch of coc but have been having trouble using it.
For some reason, whenever I enter Insert mode, this error keeps flashing:
[coc.nvim] error: at NeovimClient.emitNotification (/Users/carlosgrijalva/.vim/plugged/coc.nvim/build/index.js:1
I also attempted to install certain extensions like coc-tsserver and got the following error:
[coc.nvim] Error on install coc-tsserver: Error: coc-tsserver 1.6.3 requires coc.nvim >= >=0.0.79, please update coc
.nvim.
Not sure what's going on since i'm using the latest release. Below is my .vimrc:
" PLUGINS
" ===================================
call plug#begin('~/.vim/plugged')
Plug 'morhetz/gruvbox'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'junegunn/fzf', { 'do': { -> fzf#install()} }
Plug 'junegunn/fzf.vim'
call plug#end()
" VIM General
" ===================================
set nocompatible
syntax on
set showmode " Shows mode at bottom of window
set relativenumber " Relative number line
set showmatch " Show matching brackets.
set smartcase " Do smart case matching
set smartindent " Do smart indenting
set incsearch " Incremental search
nnoremap <Leader><space> :noh<Enter>
set number " Show line numbers
set noswapfile " Disables creating swap files
set undodir=~/.vim/undodir
set tabstop=2
set shiftwidth=2
let g:gruvbox_contrast_dark='hard'
set termguicolors
colorscheme gruvbox
set background=dark
imap jj <Esc>
let mapleader=","
You're not using the latest coc.nvim release, try to delete ~/.vim/plugged/coc.nvim and install again.

What does vim-perl plugin do that "syntax on" doesn't?

I'm trying to get vim set up as an IDE for Perl. I'm using generic, text-based vim, not gvim.
I installed the "vim-perl" addon at https://github.com/vim-perl/vim-perl using the vim addon manager per the suggestion of someone else. At least I think it's installed but I don't notice any difference in how the file is processed.
First I installed the vim-addon-manager with Debian's package manager. Then I put the following code in my .vimrc file and reloaded it:
" put this line first in ~/.vimrc
set nocompatible | filetype indent plugin on | syn on
fun! SetupVAM()
let c = get(g:, 'vim_addon_manager', {})
let g:vim_addon_manager = c
let c.plugin_root_dir = expand('$HOME', 1) . '/.vim/vim-addons'
" Force your ~/.vim/after directory to be last in &rtp always:
" let g:vim_addon_manager.rtp_list_hook = 'vam#ForceUsersAfterDirectoriesToBeLast'
" most used options you may want to use:
" let c.log_to_buf = 1
" let c.auto_install = 0
let &rtp.=(empty(&rtp)?'':',').c.plugin_root_dir.'/vim-addon-manager'
if !isdirectory(c.plugin_root_dir.'/vim-addon-manager/autoload')
execute '!git clone --depth=1 git://github.com/MarcWeber/vim-addon-manager '
\ shellescape(c.plugin_root_dir.'/vim-addon-manager', 1)
endif
" This provides the VAMActivate command, you could be passing plugin names, too
call vam#ActivateAddons([], {})
endfun
all SetupVAM()
" ACTIVATING PLUGINS
" OPTION 1, use VAMActivate
VAMActivate github:vim-perl/vim-perl
" OPTION 2: use call vam#ActivateAddons
"call vam#ActivateAddons([vim-perl], {})
use <c-x><c-p> to complete plugin names
" OPTION 3: Create a file ~/.vim-srcipts putting a PLUGIN_NAME into each line
" See lazy loading plugins section in README.md for details
" call vam#Scripts('~/.vim-scripts', {'tag_regex': '.*'})
So what exactly is the vim-perl addon supposed to do for me? I can't find any good documenation anywhere.
At least parts of vim-perl are incorporated in the factory-default configuration of Vim; cp. $VIMRUNTIME/ftplugin/perl.vim and $VIMRUNTIME/syntax/perl.vim. By installing (and regularly upgrading) the plugin, you'll get:
a newer version of the scripts, with potential enhancements and bug fixes
some additional functionality (f.e. there's a syntax/mason.vim that's not yet in Vim itself)
If you regularly edit non-trivial Perl scripts, or use latest language features, installing vim-perl is worth contemplating. If you're just a casual programmer, I would wait until a real need arises.

Where / how / in what context is ipython's configuration file executed?

Where is ipython's configuration file, which starts with c = get_config(), executed? I'm asking because I want to understand what order things are done in ipython, e.g. why certain commands will not work if included as c.InteractiveShellApp.exec_lines.
This is related to my other question, Log IPython output?, because I want access to a logger attribute, but I can't figure out how to access it in the configuration file, and by the time exec_lines are run, the logger has already started (it's too late).
EDIT: I've accepted a solution based on using a startup file in ipython0.12+. Here is my implementation of that solution:
from time import strftime
import os.path
ip = get_ipython()
#ldir = ip.profile_dir.log_dir
ldir = os.getcwd()
fname = 'ipython_log_' + strftime('%Y-%m-%d') + ".py"
filename = os.path.join(ldir, fname)
notnew = os.path.exists(filename)
try:
ip.magic('logstart -o %s append' % filename)
if notnew:
ip.logger.log_write( u"########################################################\n" )
else:
ip.logger.log_write( u"#!/usr/bin/env python\n" )
ip.logger.log_write( u"# " + fname + "\n" )
ip.logger.log_write( u"# IPython automatic logging file\n" )
ip.logger.log_write( u"# " + '# Started Logging At: '+ strftime('%Y-%m-%d %H:%M:%S\n') )
ip.logger.log_write( u"########################################################\n" )
print " Logging to "+filename
except RuntimeError:
print " Already logging to "+ip.logger.logfname
There are only two subtle differences from the proposed solution linked:
1. saves log to cwd instead of some log directory (though I like that more...)
2. ip.magic_logstart doesn't seem to exist, instead one should use ip.magic('logstart')
The config system sets up a special namespace containing the get_config() function, runs the config file, and collects the values to apply them to the objects as they're created. Referring to your previous question, it doesn't look like there's a configuration value for logging output. You may want to start logging yourself after config, when you can control it more precisely. See this example of starting logging automatically.
Your other question mentions that you're limited to 0.10.2 on one system: that has a completely different config system that won't even look at the same file.