From d5f42ba079e01430cd55904a8952929ced16df77 Mon Sep 17 00:00:00 2001 From: SunderB <20426079+SunderB@users.noreply.github.com> Date: Sat, 3 Mar 2018 17:28:57 +0000 Subject: [PATCH] Change keybindings to be more similar to Sonic Pi's; add check for active text editor; attribute euwbah/sonic-pi-autocomplete Also: update README.md to include the correct commands. --- LICENSE.md | 15 +++++++++++++-- README.md | 16 ++++++++-------- keymaps/sb-atom-sonic-pi.cson | 4 ++-- lib/sb-atom-sonic-pi.coffee | 31 ++++++++++++++++++------------- package.json | 2 +- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index c176ac9..2b231eb 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -# Copyright notice for modifications of rkh/atom-sonic in sunderb/sb-atom-sonic-pi from 24/02/2018 to present +# Copyright notice for modifications of rkh/atom-sonic in sunderb/sb-atom-sonic-pi from 24/02/2018 to present: Copyright (c) 2018 SunderB Permission is hereby granted, free of charge, to any person obtaining @@ -20,7 +20,8 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# Copyright notice for rkh/atom-sonic +# This package is a fork of [rkh/atom-sonic](https://github.com/rkh/atom-sonic) (https://github.com/rkh/atom-sonic). +# Copyright notice for rkh/atom-sonic: Copyright (c) 2015 rkh Permission is hereby granted, free of charge, to any person obtaining @@ -41,3 +42,13 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# This package contains some code from [euwbah/sonic-pi-autocomplete](https://github.com/euwbah/sonic-pi-autocomplete) (https://github.com/euwbah/sonic-pi-autocomplete). +# Copyright notice for euwbah/sonic-pi-autocomplete: +Copyright (c) 2016 euwbah + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 895bc11..2ad7a08 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sonic Pi Atom integration -This plugin, which is forked from [rkh/atom-sonic](https://github.com/rkh/atom-sonic), allows remote controlling [Sonic Pi](http://sonic-pi.net/) via [Atom](https://atom.io/). +This plugin, which is forked from [rkh/atom-sonic](https://github.com/rkh/atom-sonic) and contains a little code from [euwbah/sonic-pi-autocomplete](https://github.com/euwbah/sonic-pi-autocomplete), allows remote controlling [Sonic Pi](http://sonic-pi.net/) via [Atom](https://atom.io/). This package makes it easier to write and run your Sonic Pi code within Atom. :) @@ -13,16 +13,16 @@ The [tool-bar](https://atom.io/packages/tool-bar) package for Atom needs to be i * Adjusted OSC code to send to Sonic Pi server, and optionally to the Sonic Pi GUI (OSC messages sent to GUI appear in the cue log). * Added save-and-play-file command, which saves the current file and tells Sonic Pi to play the file. This allows for playback of large buffers. This command can be activated using F5. * Added integration with the [tool-bar](https://atom.io/packages/tool-bar) package to add buttons which run some commands to a toolbar. -* Changed some of the default key bindings (for example: `atom-sonic:stop` used `ctrl-s`, which is used as the 'save' shortcut on many systems, so I changed that to `ctrl-alt-s`), see below for the key bindings. +* Changed some of the default key bindings to be more similar to Sonic Pi's keyboard shortcuts, see below for the key bindings. * Added options to change the Sonic Pi server IP address and port, and the Sonic Pi GUI IP address and port. I'm happy to contribute these changes to rkh/atom-sonic if wanted. :) ## Commands and Default Key Bindings - Key Binding | Action | Description ---------------|--------------------------------|----------------- - `ctrl-f5` | `atom-sonic:play-file` | Sends content of the currently open buffer to Sonic Pi for instant playback. - `f5` | `atom-sonic:save-and-play-file`| Saves the current file and tells Sonic Pi to play the file. Allows for playback of large buffers. - `ctrl-alt-r` | `atom-sonic:play-selection` | Sends currently selected text to Sonic Pi for instant playback. - `ctrl-alt-s` | `atom-sonic:stop` | Tells Sonic Pi to stop all playback. + Key Binding | Action | Description +--------------|---------------------------------------|----------------- + `alt-r` | `sb-atom-sonic-pi:play-file` | Sends content of the currently open buffer to Sonic Pi for instant playback. + `f5` | `sb-atom-sonic-pi:save-and-play-file` | Saves the current file and tells Sonic Pi to play the file. Allows for playback of large buffers. + `ctrl-alt-r` | `sb-atom-sonic-pi:play-selection` | Sends currently selected text to Sonic Pi for instant playback. + `alt-s` | `sb-atom-sonic-pi:stop` | Tells Sonic Pi to stop all playback. diff --git a/keymaps/sb-atom-sonic-pi.cson b/keymaps/sb-atom-sonic-pi.cson index 2fdfc91..a58fa3d 100644 --- a/keymaps/sb-atom-sonic-pi.cson +++ b/keymaps/sb-atom-sonic-pi.cson @@ -8,7 +8,7 @@ # For more detailed documentation see # https://atom.io/docs/latest/behind-atom-keymaps-in-depth 'atom-workspace': - 'ctrl-f5': 'sb-atom-sonic-pi:play-file' + 'alt-r': 'sb-atom-sonic-pi:play-file' 'f5': 'sb-atom-sonic-pi:save-and-play-file' 'ctrl-alt-r': 'sb-atom-sonic-pi:play-selection' - 'ctrl-alt-s': 'sb-atom-sonic-pi:stop' + 'alt-s': 'sb-atom-sonic-pi:stop' diff --git a/lib/sb-atom-sonic-pi.coffee b/lib/sb-atom-sonic-pi.coffee index 7f2220c..c0e53e7 100644 --- a/lib/sb-atom-sonic-pi.coffee +++ b/lib/sb-atom-sonic-pi.coffee @@ -3,7 +3,7 @@ {CompositeDisposable} = require 'atom'; osc = require 'node-osc'; provider = require './sb-atom-sonic-pi-autocomplete'; -sbAtomSonicPiView = require './sb-atom-sonic-pi-view'; # for test_toggle +sbAtomSonicPiView = require './sb-atom-sonic-pi-view'; # for sbAtomSonicPiView module.exports = sbAtomSonicPi = config: # Settings @@ -37,9 +37,9 @@ module.exports = sbAtomSonicPi = type: 'boolean', default: false order: 5 - sbAtomSonicPiView: null; # for test_toggle + sbAtomSonicPiView: null; # for sbAtomSonicPiView subscriptions: null; - modalPanel: null; # for test_toggle + modalPanel: null; # for sbAtomSonicPiView provide: -> provider; activate: (state) -> @@ -116,26 +116,31 @@ module.exports = sbAtomSonicPi = # Remove any toolbar items added @toolBar.removeItems(); @toolBar = null; - @modalPanel.destroy(); # for test_toggle + @modalPanel.destroy(); # for sbAtomSonicPiView @subscriptions.dispose(); - @sbAtomSonicPiView.destroy(); # for test_toggle + @sbAtomSonicPiView.destroy(); # for sbAtomSonicPiView serialize: -> return sbAtomSonicPiViewState: this.sbAtomSonicPiView.serialize(); # for test_toggle play: (selector) -> editor = atom.workspace.getActiveTextEditor(); - source = editor[selector](); - @send('/run-code', 'atom', source); - atom.notifications.addSuccess("Sent source code to Sonic Pi."); + if editor == undefined + atom.notifications.addError("No active text editor found.") + else + source = editor[selector](); + @send('/run-code', 'atom', source); + atom.notifications.addSuccess("Sent source code to Sonic Pi."); saveAndPlay: -> editor = atom.workspace.getActiveTextEditor(); - editor.save(); - fullPath = editor.getPath().replace(/\\/g,"/"); - title = editor.getTitle(); - @send('/run-code', 'atom', "run_file \"" + fullPath + "\""); - atom.notifications.addSuccess("Saved file and told Sonic Pi to start playing."); + if editor == undefined + atom.notifications.addError("No active text editor found."); + else + editor.save(); + fullPath = editor.getPath().replace(/\\/g,"/"); # Replace back-slashes in the file path with forward-slashes. Useful for Windows file paths. + @send('/run-code', 'atom', "run_file \"" + fullPath + "\""); + atom.notifications.addSuccess("Saved file and told Sonic Pi to start playing."); stop: -> @send('/stop-all-jobs'); diff --git a/package.json b/package.json index 708f280..d0a0d96 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sb-atom-sonic-pi", "main": "./lib/sb-atom-sonic-pi", - "version": "1.0.0-dev.03-03-2018-1", + "version": "1.0.0-dev.03-03-2018-2", "description": "Sonic Pi Atom integration. Based on rkh/atom-sonic.", "keywords": [], "providedServices": {