Coder Social home page Coder Social logo

sonicpi.nvim's Introduction

sonicpi.nvim

This is a neovim plugin for Sonic Pi

Screenshot

Features

This plugin is inspired by sonicpi.vim.

But

  • fully implemented in lua.
  • dynamic completion engine, powered by nvim-cmp.
    • help texts and completions are parsed from Sonic Pi's server code
  • not dependend on external tools
  • Compatible with Sonic Pi v4.0 and higher
    • can start and stop the Sonic Pi daemon process and sends the proper keep-alive packets in the background
  • Can show logs and cues coming from Sonic Pi

Installation

You will need at least version 0.6 of neovim with lua support and nvim-cmp. Use your preferred package/plugin manager to install this plugin. With packer.nvim, this looks like:

use({
  'magicmonty/sonicpi.nvim',
  config = function()
    require('sonicpi').setup()
  end,
  requires ='hrsh7th/nvim-cmp',
    'kyazdani42/nvim-web-devicons'
  }
})

You have to set the directory to the Sonic Pi server, so that the plugin can read the documentation and language arguments for the completion engine.

Configuration

The default configuration is as follows, you can override it with your own settings if you wish

require('sonicpi').setup({
  server_dir = "", -- It will try to find the SonicPi server
  lsp_diagnostics = false -- enable LSP diagnostics
  mappings = {
    { 'n', '<leader>s', require('sonicpi.remote').stop, default_mapping_opts },
    { 'i', '<M-s>', require('sonicpi.remote').stop, default_mapping_opts },
    { 'n', '<leader>r', require('sonicpi.remote').run_current_buffer, default_mapping_opts },
    { 'i', '<M-r>', require('sonicpi.remote').run_current_buffer, default_mapping_opts },
  },
})

LSP setup

If you want to use the LSP, then install solargraph correctly and add the following to the on_init callback of your lsp config:

local function on_init(client)
  ...

  require('sonicpi').lsp_on_init(client, { server_dir = '/opt/sonic-pi/app/server' })
end

also you need to configure solargraph to accept single files with

single_file = true

in the solargraph settings for your LSP setup

CMP setup

If you want to use the completion engine, then you have to add the sonicpi source to your config:

require('cmp').setup({
  ...

  sources = {
    ...
    { name = 'sonicpi' }
    ...
  },
})

Luasnip

This plugin has support for Luasnip. If you have luasnip istalled, then a selection of predefined snippets will be available.

Currently the following snippets are available:

  • clocks -> makes a live loop, which acts as a selection of clocks where you can synchronize to
  • ll -> makes a live loop
  • llc -> makes a live loop, which synchronizes to a specific clock cue
  • bd -> makes a live loop with a four on the floor base drum pattern
  • fx -> makes a generic with_fx block
  • echo -> makes a with_fx block with echo settings
  • reverb -> makes a with_fx block with reverb settings

Usage

You need to create a new file with a .sonicpi extension and open it in neovim. Then you can use the LSP and completion engine including the snippets.

Commands

  • SonicPiStartDaemon: Starts the Sonic Pi server processes and keeps them alive
  • SonicPiStopDaemon: Stops the Sonic Pi server processes
  • SonicPiHideLogs: Hides the log windows but keeps the buffers intact (logging continues in the background)
  • SonicPiCloseLogs: Closes all log windows and stops listening for log messages
  • SonicPiStopAndClose: A combination of SonicPiStopDaemon and SonicPiCloseLogs
  • SonicPiSendBuffer: Sends the content of the buffer to Sonic Pi for execution
  • SonicPiStop: Stops the current run

Default Mappings

Mode Key binding Description
n <leader>r Run current buffer
n <leader>s Stop execution
i <M-r> Run current buffer
i <M-s> Stop execution

sonicpi.nvim's People

Contributors

elahi-cs avatar magicmonty avatar primalmotion avatar timwmillard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sonicpi.nvim's Issues

where can I find `daemon.rb`?

When I open a file test.sonicpi and execute :SonicPiStartDaemon then I get this error.
Maybe that means that I configured something incorrectly?

Error executing Lua callback: ...ocal/share/nvim/plugged/plenary.nvim/lua/plenary/job.lua:405: Failed to spawn process: {                                                                                                                      
  _additional_on_exit_callbacks = {},                                                                                                                                                                                                          
  _raw_cwd = "/ruby/bin",                                                                                                                                                                                                                      
  _shutdown_check = <userdata 1>,                                                                                                                                                                                                              
  _stderr_results = {},                                                                                                                                                                                                                        
  _stdout_results = {},                                                                                                                                                                                                                        
  _user_on_exit = <function 1>,                                                                                                                                                                                                                
  _user_on_stdout = <function 2>,                                                                                                                                                                                                              
  args = { "daemon.rb" },                                                                                                                                                                                                                      
  command = "ruby",                                                                                                                                                                                                                            
  enable_handlers = true,                                                                                                                                                                                                                      
  enable_recording = true,                                                                                                                                                                                                                     
  interactive = true,                                                                                                                                                                                                                          
  pid = "ENOENT: no such file or directory",                                                                                                                                                                                                   
  stderr = <userdata 2>,                                                                                                                                                                                                                       
  stdin = <userdata 3>,                                                                                                                                                                                                                        
  stdout = <userdata 4>,                                                                                                                                                                                                                       
  user_data = {},                                                                                                                                                                                                                              
  <metatable> = <1>{                                                                                                                                                                                                                           
    __index = <table 1>,                                                                                                                                                                                                                       
    _create_uv_options = <function 3>,                                                                                                                                                                                                         
    _execute = <function 4>,                                                                                                                                                                                                                   
    _pipes_are_closed = <function 5>,                                                                                                                                                                                                          
    _prepare_pipes = <function 6>,                                                                                                                                                                                                             
    _reset = <function 7>,                                                                                                                                                                                                                     
    _shutdown = <function 8>,                                                                                                                                                                                                                  
    _stop = <function 9>,                                                                                                                                                                                                                      
    add_on_exit_callback = <function 10>,                                                                                                                                                                                                      
    after = <function 11>,                                                                                                                                                                                                                     
    after_failure = <function 12>,                                                                                                                                                                                                             
    after_success = <function 13>,                                                                                                                                                                                                             
    and_then = <function 14>,                                                                                                                                                                                                                  
    and_then_on_failure = <function 15>,                                                                                                                                                                                                       
    and_then_on_failure_wrap = <function 16>,                                                                                                                                                                                                  
    and_then_on_success = <function 17>,                                                                                                                                                                                                       
    and_then_on_success_wrap = <function 18>,                                                                                                                                                                                                  
    and_then_wrap = <function 19>,                                                                                                                                                                                                             
    chain = <function 20>,                                                                                                                                                                                                                     
    chain_status = <function 21>,                                                                                                                                                                                                              
    co_wait = <function 22>,                                                                                                                                                                                                                   
    is_job = <function 23>,                                                                                                                                                                                                                    
    join = <function 24>,                                                                                                                                                                                                                      
    new = <function 25>,                                                                                                                                                                                                                       
    pid = <function 26>,                                                                                                                                                                                                                       
    result = <function 27>,                                                                                                                                                                                                                    
    send = <function 28>,                                                                                                                                                                                                                      
    shutdown = <function 29>,                                                                                                                                                                                                                  
    start = <function 30>,                                                                                                                                                                                                                     
    stderr_result = <function 31>,                                                                                                                                                                                                             
    sync = <function 32>,                                                                                                                                                                                                                      
    wait = <function 33>                                                                                                                                                                                                                       
  }                                                                                                                                                                                                                                            
}
stack traceback:                                                                                                                                                                                                                               
        ...ocal/share/nvim/plugged/plenary.nvim/lua/plenary/job.lua:405: in function '_execute'                                                                                                                                                
        ...ocal/share/nvim/plugged/plenary.nvim/lua/plenary/job.lua:448: in function 'start'                                                                                                                                                   
        ...l/share/nvim/plugged/sonicpi.nvim/lua/sonicpi/remote.lua:148: in function <...l/share/nvim/plugged/sonicpi.nvim/lua/sonicpi/remote.lua:107>                                                                                         
stack traceback:                                                                                                                                                                                                                               
        [C]: in function 'error'                                                                                                                                                                                                               
        ...ocal/share/nvim/plugged/plenary.nvim/lua/plenary/job.lua:405: in function '_execute'                                                                                                                                                
        ...ocal/share/nvim/plugged/plenary.nvim/lua/plenary/job.lua:448: in function 'start'                                                                                                                                                   
        ...l/share/nvim/plugged/sonicpi.nvim/lua/sonicpi/remote.lua:148: in function <...l/share/nvim/plugged/sonicpi.nvim/lua/sonicpi/remote.lua:107>

My synthinfo.rb file is in other directory than the plugin expects it to be

I get this error:

E5108: Error executing lua ...share/nvim/plugged/sonicpi.nvim/lua/cmp-sonicpi/util.lua:307: bad argument #1 to 'lines' (/usr/lib/sonic-pi/server/ruby/lib/sonicpi/synths/synthinfo.rb: No such file or directory)

My server URL was this: '/usr/lib/sonic-pi/server'

But when I ask where it installed the file it gives me lib directory:

pacman -Ql sonic-pi  | grep synthinfo.rb
sonic-pi /usr/lib/sonic-pi/server/lib/sonicpi/synths/synthinfo.rb

But when I remove the directory as indicated in the tutorial then it finds it correctly, I guess. Not sure yet.

Failed to run `config` for sonicpi.nvim

After installing the plugin with lazy.nvim and trying to open a .sonicpi file with nvim I get the following error:

Failed to run `config` for sonicpi.nvim
...a/Local/nvim-data/lazy/sonicpi.nvim/lua/sonicpi/init.lua:109: attempt to index local 'opts' (a nil value)
# stacktrace:
  - sonicpi.nvim\lua\sonicpi\init.lua:109 _in_ **setup**
  - ~/AppData/Local/nvim/lua/packages/sonicpi.lua:8 _in_ **config**
  - ~\AppData\Local\nvim\init.lua:21

This is the sonicpi.lua file referenced in the second line of the stack trace:

return {
    'magicmonty/sonicpi.nvim',
    dependencies = {
        'hrsh7th/nvim-cmp',
        'kyazdani42/nvim-web-devicons'
    },
    config = function()
        require('sonicpi').setup()
    end,
}

I haven't done any LSP or CMP setups in case this might be related.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.