Skip to content

Commit

Permalink
Add some partial syntax highlighting and snippets support for Sonic P…
Browse files Browse the repository at this point in the history
…i functions; add command to open online tutorial; add title to toolbar

Also, update README.md
  • Loading branch information
SunderB committed Jan 31, 2021
1 parent c53e54d commit ea2eb8d
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 16 deletions.
33 changes: 33 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,36 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
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.

## This package contains some code from [atom/language-ruby](https://github.com/atom/language-ruby) (https://github.com/atom/language-ruby). Below is the license from [atom/language-ruby](https://github.com/atom/language-ruby) (retrieved 30/01/2021):
Copyright (c) 2014 GitHub Inc.

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.

--------------------------------------------------------------------

This package was derived from a TextMate bundle located at
https://github.com/textmate/ruby.tmbundle and distributed under the following
license, located in `README.mdown`:

Permission to copy, use, modify, sell and distribute this
software is granted. This software is provided "as is" without
express or implied warranty, and with no claim as to its
suitability for any purpose.
35 changes: 27 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# Sonic Pi Atom integration

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. :)

For a list of releases in chronological order, see [the Releases wiki page](https://github.com/SunderB/sb-atom-sonic-pi/wiki/Releases).
This package makes it easier to write and run your [Sonic Pi](http://sonic-pi.net/) code within Atom. :)
NOTE: This package may not be regularly maintained. This is not an official package.

## Features
* Control Sonic Pi from Atom:
- Play a buffer
- Stop the current runs
- Save a buffer and tell Sonic Pi to play it - allowing for playback of large buffers
- Play a selection
* Keyboard shortcuts (similar to Sonic Pi's shortcuts) to activate the commands
* The server IP and port can be changed in the settings
* Integration with the [tool-bar](https://atom.io/packages/tool-bar) package
* Auto-completions for (most) synths, FX, and samples (not nearly as well integrated as the official Sonic Pi GUI though)
* Very partial syntax highlighting and snippets for Sonic Pi functions
* Quick action to access the online tutorial from your web browser

This isn't a full client for Sonic Pi; it requires the server to already be running and doesn't have support for viewing the logs, closing the server etc.

## Requirements

Sonic Pi needs to be running in the background.
**Sonic Pi needs to be running in the background.**
The [tool-bar](https://atom.io/packages/tool-bar) package for Atom needs to be installed to use the toolbar functionality.

## Changes from rkh/atom-sonic
Expand All @@ -26,6 +37,14 @@ I'm happy to contribute these changes to rkh/atom-sonic if wanted. :)
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. (If used with an **untitled** file, it opens a save-as dialog box to allow you to save the file.)
`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. (If used with an *untitled* file, it opens a save-as dialog box to allow you to save the file.)
`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.
`alt-i` | `sb-atom-sonic-pi:open_tutorial` | Open the online Sonic-Pi tutorial in your system's web browser (https://sonic-pi.net/tutorial)

## Credit
* This package was originally forked from [rkh/atom-sonic](https://github.com/rkh/atom-sonic)
* Some code in this package comes from [euwbah/sonic-pi-autocomplete](https://github.com/euwbah/sonic-pi-autocomplete) and [atom/language-ruby](https://github.com/atom/language-ruby)

## License
This package is licensed under the MIT License. See [LICENSE.md](LICENSE.md) for the full license.
74 changes: 74 additions & 0 deletions grammars/sonic-pi.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'name': 'Sonic Pi'
'scopeName': 'source.ruby.sonic-pi'
'fileTypes': [
'.rb'
]
'patterns': [
{
'include': 'source.ruby'
}
{ # Sonic Pi functions - incomplete
'begin': '\\b(?<!\\.|::)(play|chord|chord_invert|stop|cue|sync|in_thread|live_loop|print|use_synth|with_fx|with_synth|with_synth_defaults)\\b(?![?!])'
'captures':
'1':
'name': 'keyword.other.special-method.ruby.sonic-pi'
'end': '$|(?=#|})'
'name': 'meta.declaration.ruby.sonic-pi'
'patterns': [
{
'include': '$self'
}
]
}
# { # define
# 'begin': '''(?x)
# (?=define\\b) # optimization to help Oniguruma fail fast
# (?<=^|\\s)(def)\\s+
# (
# (?>[a-zA-Z_]\\w*(?>\\.|::))? # method prefix
# (?> # method name
# [a-zA-Z_]\\w*(?>[?!]|=(?!>))?
# |
# ===?|!=|>[>=]?|<=>|<[<=]?|[%&`/\\|]|\\*\\*?|=?~|[-+]@?|\\[]=?
# )
# )
# \\s*(\\()
# '''
# 'beginCaptures':
# '1':
# 'name': 'keyword.control.def.ruby'
# '2':
# 'name': 'entity.name.function.ruby'
# '3':
# 'name': 'punctuation.definition.parameters.ruby'
# 'comment': 'The method pattern comes from the symbol pattern. See there for an explanation.'
# 'end': '\\)'
# 'endCaptures':
# '0':
# 'name': 'punctuation.definition.parameters.ruby'
# 'name': 'meta.function.method.with-arguments.ruby'
# 'patterns': [
# {
# 'begin': '(?![\\s,)])'
# 'end': '(?=,|\\)\\s*$)'
# 'patterns': [
# {
# 'captures':
# '1':
# 'name': 'storage.type.variable.ruby'
# '2':
# 'name': 'constant.other.symbol.hashkey.parameter.function.ruby'
# '3':
# 'name': 'punctuation.definition.constant.hashkey.ruby'
# '4':
# 'name': 'variable.parameter.function.ruby'
# 'match': '\\G([&*]?)(?:([_a-zA-Z]\\w*(:))|([_a-zA-Z]\\w*))'
# }
# {
# 'include': '$self'
# }
# ]
# }
# ]
# }
]
1 change: 1 addition & 0 deletions keymaps/sb-atom-sonic-pi.cson
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
'f5': 'sb-atom-sonic-pi:save-and-play-file'
'ctrl-alt-r': 'sb-atom-sonic-pi:play-selection'
'alt-s': 'sb-atom-sonic-pi:stop'
'alt-i': 'sb-atom-sonic-pi:open_tutorial'
42 changes: 34 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ module.exports = (sbAtomSonicPi = {
'sb-atom-sonic-pi:stop': {
displayName: 'Sonic Pi: Stop Playing Code',
didDispatch: () => this.stop()
},
'sb-atom-sonic-pi:open_tutorial': {
displayName: 'Sonic Pi: Open Online Tutorial',
didDispatch: () => this.open_tutorial()
}
})
//'sb-atom-sonic-pi:test_toggle': => @test_toggle()
Expand All @@ -95,6 +99,14 @@ module.exports = (sbAtomSonicPi = {
// Add spacer
this.toolBar.addSpacer();

let label_element = document.createElement('h2')
label_element.innerHTML = "Sonic Pi"
const label = this.toolBar.addItem({
element: label_element
})

this.toolBar.addSpacer();

// Add buttons
const button_play = this.toolBar.addButton({
icon: 'md-play',
Expand All @@ -103,17 +115,26 @@ module.exports = (sbAtomSonicPi = {
iconset: 'ion'
});

const button_stop = this.toolBar.addButton({
icon: 'md-square',
callback: 'sb-atom-sonic-pi:stop',
tooltip: 'Stop Playing Code',
iconset: 'ion'
});

const button_saveAndPlayFile = this.toolBar.addButton({
icon: 'md-download',
callback: 'sb-atom-sonic-pi:save-and-play-file',
tooltip: 'Save and Play File',
iconset: 'ion'
});

const button_stop = this.toolBar.addButton({
icon: 'md-square',
callback: 'sb-atom-sonic-pi:stop',
tooltip: 'Stop Playing Code',
this.toolBar.addSpacer();

const button_openTutorial = this.toolBar.addButton({
icon: 'md-book',
callback: 'sb-atom-sonic-pi:open_tutorial',
tooltip: 'Open Online Tutorial',
iconset: 'ion'
});

Expand Down Expand Up @@ -142,6 +163,11 @@ module.exports = (sbAtomSonicPi = {
return {sbAtomSonicPiViewState: this.sbAtomSonicPiView.serialize()};
}, // for test_toggle

open_tutorial() {
electron.shell.openExternal("https://sonic-pi.net/tutorial");
return atom.notifications.addInfo("Opened the Online Sonic Pi Tutorial.");
},

play(selector) {
const editor = atom.workspace.getActiveTextEditor();
if (editor === undefined) {
Expand Down Expand Up @@ -215,11 +241,11 @@ module.exports = (sbAtomSonicPi = {

send(...args) {
// Get IP addresses and ports
const sp_server_ip = atom.config.get('sb-atom-sonic-pi.sonicPiServerIP'); // default: 127.0.0.1
const sp_server_port = atom.config.get('sb-atom-sonic-pi.sonicPiServerPort'); // default: 4557
const sp_server_ip = atom.config.get('sb-atom-sonic-pi.sonicPiServerIP');
const sp_server_port = atom.config.get('sb-atom-sonic-pi.sonicPiServerPort');

const sp_gui_ip = atom.config.get('sb-atom-sonic-pi.sonicPiGUIIP'); // default: 127.0.0.1
const sp_gui_port = atom.config.get('sb-atom-sonic-pi.sonicPiGUIPort'); // default: 4559
const sp_gui_ip = atom.config.get('sb-atom-sonic-pi.sonicPiGUIIP');
const sp_gui_port = atom.config.get('sb-atom-sonic-pi.sonicPiGUIPort');

// Send OSC messages
if (atom.config.get('sb-atom-sonic-pi.sendOSCMessagesToGUI') === true) {
Expand Down
4 changes: 4 additions & 0 deletions menus/sb-atom-sonic-pi.cson
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
{
'label': 'Stop Playing Code'
'command': 'sb-atom-sonic-pi:stop'
},
{
'label': 'Open Online Tutorial'
'command': 'sb-atom-sonic-pi:open_tutorial'
}
]
]
Expand Down
20 changes: 20 additions & 0 deletions snippets/sonic-pi.cson
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'.source.ruby.sonic-pi':
# Incomplete
'in_thread do … end':
'prefix': 'in_thread'
'body': 'in_thread do\n\t$1\nend'
'live_loop do … end':
'prefix': 'live_loop'
'body': 'live_loop :${1:name} do\n\t$2\nend'
'live_loop sync:… do … end':
'prefix': 'live_loop sync'
'body': 'live_loop :${1:name} sync: ${2:cue_name} do\n\t$3\nend'
'with_synth do ... end':
'prefix': 'with_synth'
'body': 'with_synth :${1:synth} do\n\t$2\nend'
'with_fx do ... end':
'prefix': 'with_fx'
'body': 'with_fx :${1:fx} ${2:opts} do\n\t$3\nend'
'with_synth_defaults do ... end':
'prefix': 'with_synth_defaults'
'body': 'with_synth_defaults ${1:opts} do\n\t$3\nend'

0 comments on commit ea2eb8d

Please sign in to comment.