├── .gitignore ├── ftdetect └── csound.vim ├── README.md ├── LICENSE ├── doc └── csound-repl.txt └── ftplugin └── csound.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /ftdetect/csound.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead *.orc,*.sco,*.csd,*.udo setfiletype csound 2 | "au BufNewFile,BufRead *.csd runtime! macros/csound.vim 3 | 4 | "au FileType csound execute 'setlocal dict=:p:h:h/words/csound.txt' 5 | "au FileType csound execute 'setlocal complete=k' 6 | "au FileType csound execute 'setlocal completeopt=longest,menuone' 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # csound-repl.vim 2 | 3 | Vim script to live code with Csound. 4 | 5 | For more information, please see the [plugin documentation](doc/csound-repl.txt). 6 | 7 | ## Requirements 8 | 9 | * Vim with either python or python3 support enabled 10 | 11 | ## Installation 12 | 13 | This repository is designed to work plugin managers like Pathogen or Vundle. 14 | For example, using Vundle, you can use the following entry in your .vimrc file: 15 | 16 | ```Plugin "kunstmusik/csound-repl"``` 17 | 18 | 19 | ## License 20 | 21 | Copyright © Steven Yi. Distributed under the MIT license. 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2016 Steven Yi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /doc/csound-repl.txt: -------------------------------------------------------------------------------- 1 | *csound-repl.txt* Plugin for live coding with Csound 2 | 3 | Author: Steven Yi 4 | License: MIT 5 | 6 | INTRODUCTION *csound-repl* 7 | 8 | This plugin provides basic functionality to send Csound code over UDP to a 9 | running instance of Csound. This will allow you to interactively evaluate and 10 | compile new instruments and UDOs, update existing instruments and UDOs, as 11 | well as execute opcode calls in instrument 0 space. 12 | 13 | This plugin is best used together with Luis Jure's csound-vim plugin 14 | (https://github.com/ljure/csound). 15 | 16 | REQUIREMENTS *csound-repl:requirements* 17 | 18 | This plugin requires that the version of Vim used has Python or Python3 support built-in. 19 | 20 | FILE TYPES *csound-repl:filetypes* 21 | 22 | csound-repl work with csound filetypes (i.e., .orc, .sco, .csd, .udo). 23 | 24 | 25 | SETTING UP CSOUND REPL *csound-repl:setup* 26 | 27 | csound-repl is preconfigured to run with UDP port 10000. If you need to use a 28 | different port, execute the command ":call Csound_set_port(portNumber)" with 29 | the port number you would like to use. 30 | 31 | Currently, Csound itself should be started in a separate terminal with the 32 | --port command. For example: 33 | 34 | csound --port=10000 some.csd 35 | 36 | This will begin Csound in server mode and evaluate some.csd as initial code. 37 | Once Csound is running, you will be able to use this plugin to evaluate and 38 | send code to that running Csound instance. 39 | 40 | EVALUATING CODE *csound-repl:eval* 41 | 42 | 43 | *csound-repl:evaluate_orc* 44 | eo In visual mode, evaluates selected Csound code as 45 | Orchestra code. 46 | 47 | In normal mode, it will select the surrounding UDO or 48 | instrument (if found) and evaluate that. Otherwise, 49 | will evaluate the current line. 50 | 51 | *csound-repl:evaluate_sco* 52 | es Evaluate selected Csound code as Score code. 53 | (Does not currently work as Csound Server mode only 54 | accepts orchestra code at this time.) 55 | 56 | 57 | ABOUT *csound-repl:about* 58 | 59 | Grab the latest version or report a bug on GitHub: 60 | 61 | http://github.com/kunstmusik/csound-repl 62 | 63 | 64 | vim:tw=78:ts=8:ft=help:norl: 65 | -------------------------------------------------------------------------------- /ftplugin/csound.vim: -------------------------------------------------------------------------------- 1 | " Csound REPL functionality 2 | " https://github.com/kunstmusik/csound-vim-repl 3 | " Language: csound 4 | " Maintainer: Steven Yi 5 | " License: MIT 6 | " Version: 1.0 7 | 8 | if !exists("g:csound_repl_load") || &cp 9 | let g:csound_repl_load = 1 10 | if(has('python')) 11 | 12 | python << EOF 13 | import socket 14 | import vim 15 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 16 | 17 | server = "127.0.0.1" 18 | port = 10000 19 | EOF 20 | 21 | elseif(has('python3')) 22 | python3 << EOF 23 | import socket 24 | import vim 25 | sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 26 | 27 | server = "127.0.0.1" 28 | port = 10000 29 | EOF 30 | 31 | else 32 | echom "Error: Csound REPL requires python." 33 | endif 34 | endif 35 | 36 | function! s:send_to_csound(payload) 37 | if(has('python')) 38 | python << EOF 39 | message = vim.eval("a:payload") 40 | sock.sendto(message, (server, port)) 41 | EOF 42 | elseif(has('python3')) 43 | 44 | python3 << EOF 45 | message = vim.eval("a:payload").encode() 46 | sock.sendto(message, (server, port)) 47 | EOF 48 | else 49 | echom "Error: csound-repl requires python" 50 | endif 51 | endfunction 52 | 53 | function! Csound_set_port(port) 54 | python port = vim.eval("a:port") 55 | endfunction 56 | 57 | function! Csound_eval_orc() 58 | normal! `y 59 | call s:send_to_csound(@@) 60 | endfunction 61 | 62 | 63 | function! Csound_eval_sco() 64 | normal! `y 65 | call s:send_to_csound("$" . @@) 66 | endfunction 67 | 68 | function! Csound_eval_orc_n() 69 | let savepos = getpos(".") 70 | let start = search('^\s*instr', 'bc') 71 | let end = search('^\s*endin', 'c') 72 | 73 | echom savepos[1] . " | " . start . " | " . end 74 | 75 | call setpos('.', [0, savepos[1], 0, 0]) 76 | let startop = search('^\s*opcode', 'bc') 77 | let endop = search('^\s*endop', 'c') 78 | 79 | if savepos[1] >= startop && savepos[1] <= endop 80 | call s:send_to_csound(join(getline(startop,endop), "\n")) 81 | call setpos('.', [0, startop, 0, 0]) 82 | exec "normal V" 83 | call setpos('.', [0, endop,0,0]) 84 | elseif savepos[1] >= start && savepos[1] <= end 85 | call s:send_to_csound(join(getline(start,end), "\n")) 86 | call setpos('.', [0, start, 0, 0]) 87 | exec "normal V" 88 | call setpos('.', [0, end,0,0]) 89 | else 90 | call s:send_to_csound(getline(savepos[1])) 91 | call setpos('.', [0, savepos[1], 0, 0]) 92 | exec "normal V" 93 | endif 94 | 95 | redraw 96 | sleep 200 m 97 | exec "normal vv" 98 | call setpos('.', savepos) 99 | endfunction 100 | 101 | 102 | function! Csound_insert_hexplay() 103 | let l:fadeCounter = get(b:, "fadeCounter", 5) 104 | let b:fadeCounter = l:fadeCounter + 1 105 | 106 | "This is depending upon the formatting rules of user's Vim to look alright 107 | let l:hexCode = "hexplay(\"8\", \n" . 108 | \ " \"Sub5\", p3,\n" . 109 | \ "in_scale(-1, 0),\n" . 110 | \ "fade_in(" . l:fadeCounter . ", 128) * ampdbfs(-12))\n" 111 | return l:hexCode 112 | endfunction 113 | 114 | function! Csound_insert_euclidplay() 115 | let l:fadeCounter = get(b:, "fadeCounter", 5) 116 | let b:fadeCounter = l:fadeCounter + 1 117 | 118 | "This is depending upon the formatting rules of user's Vim to look alright 119 | let l:euclidCode = "euclidplay(13, 32,\n" . 120 | \ " \"Sub5\", p3,\n" . 121 | \ "in_scale(-1, 0),\n" . 122 | \ "fade_in(" . l:fadeCounter . ", 128) * ampdbfs(-12))\n" 123 | return l:euclidCode 124 | endfunction 125 | 126 | function! Csound_insert_hexdirt() 127 | let l:fadeCounter = get(b:, "fadeCounter", 5) 128 | let b:fadeCounter = l:fadeCounter + 1 129 | 130 | "This is depending upon the formatting rules of user's Vim to look alright 131 | let l:code = "hexdirt(\"8\",\n" . 132 | \ " \"bd:0\", \n" . 133 | \ "fade_in(" . l:fadeCounter . ", 128) * ampdbfs(-12))\n" 134 | return l:code 135 | endfunction 136 | 137 | 138 | vnoremap eo :call Csound_eval_orc() 139 | nnoremap eo :call Csound_eval_orc_n() 140 | 141 | vnoremap es :call Csound_eval_sco() 142 | inoremap = Csound_insert_hexplay() 143 | inoremap = Csound_insert_euclidplay() 144 | inoremap = Csound_insert_hexdirt() 145 | --------------------------------------------------------------------------------