forked from rkh/atom-sonic
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sb-atom-sonic-pi-view, add test_toggle commands, start to prepare…
… for possible Sonic Pi tutorial integration, and tweak other things Tweak other things. E.g. add more brackets and semi colons to make it look more organised.
- Loading branch information
Showing
5 changed files
with
105 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use babel'; | ||
|
||
export default class sbAtomSonicPiView { | ||
|
||
constructor(serializedState) { | ||
console.log('creating element'); | ||
// Create root element | ||
this.element = document.createElement('div'); | ||
this.element.classList.add('sb-atom-sonic-pi'); | ||
|
||
// Create message element | ||
const message = document.createElement('div'); | ||
message.textContent = 'The sb-atom-sonic-pi package is Alive! It\'s ALIVE!'; | ||
message.classList.add('message'); | ||
this.element.appendChild(message); | ||
} | ||
|
||
// Returns an object that can be retrieved when package is activated | ||
serialize() {} | ||
|
||
// Tear down any state and detach | ||
destroy() { | ||
console.log('removing element'); | ||
this.element.remove(); | ||
} | ||
|
||
getElement() { | ||
return this.element; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,78 @@ | ||
{CompositeDisposable} = require 'atom' | ||
osc = require 'node-osc' | ||
provider = require './sb-atom-sonic-pi-autocomplete' | ||
'use babel'; | ||
|
||
{CompositeDisposable} = require 'atom'; | ||
osc = require 'node-osc'; | ||
provider = require './sb-atom-sonic-pi-autocomplete'; | ||
sbAtomSonicPiView = require './sb-atom-sonic-pi-view'; | ||
|
||
module.exports = sbAtomSonicPi = | ||
config: | ||
sendMessagesToGUI: | ||
title: 'Send Messages To GUI' | ||
type: 'boolean' | ||
title: 'Send Messages To GUI', | ||
type: 'boolean', | ||
default: false | ||
subscriptions: null | ||
provide: -> provider | ||
sbAtomSonicPiView: null, | ||
subscriptions: null, | ||
modalPanel: null, | ||
provide: -> provider; | ||
|
||
activate: (state) -> | ||
@subscriptions = new CompositeDisposable | ||
@sbAtomSonicPiView = new sbAtomSonicPiView(state.sbAtomSonicPiViewState); | ||
@modalPanel = atom.workspace.addModalPanel( | ||
item: this.sbAtomSonicPiView.getElement(), | ||
visible: false | ||
); | ||
|
||
@subscriptions = new CompositeDisposable; | ||
@subscriptions.add(atom.commands.add 'atom-workspace', | ||
'sb-atom-sonic-pi:play-file': => @play('getText'), | ||
'sb-atom-sonic-pi:save-and-play-file':=> @saveAndPlay(), | ||
'sb-atom-sonic-pi:play-selection': => @play('getSelectedText'), | ||
'sb-atom-sonic-pi:stop': => @stop()) | ||
'sb-atom-sonic-pi:stop': => @stop(), | ||
'sb-atom-sonic-pi:toggle-tutorial': => @toggleTutorial(), | ||
'sb-atom-sonic-pi:test_toggle': => @test_toggle() | ||
); | ||
|
||
deactivate: -> | ||
@subscriptions.dispose() | ||
@modalPanel.destroy(); | ||
@subscriptions.dispose(); | ||
@sbAtomSonicPiView.destroy(); | ||
|
||
serialize: -> | ||
return sbAtomSonicPiViewState: this.sbAtomSonicPiView.serialize(); | ||
|
||
play: (selector) -> | ||
editor = atom.workspace.getActiveTextEditor() | ||
source = editor[selector]() | ||
@send '/run-code', 'atom', source | ||
atom.notifications.addSuccess "Sent source code to Sonic Pi. :)" | ||
editor = atom.workspace.getActiveTextEditor(); | ||
source = editor[selector](); | ||
@send('/run-code', 'atom', source); | ||
atom.notifications.addSuccess("Sent source code to Sonic Pi. :)"); | ||
|
||
saveAndPlay: -> | ||
editor = atom.workspace.getActiveTextEditor() | ||
editor = atom.workspace.getActiveTextEditor(); | ||
editor.save(); | ||
fullPath = editor.getPath() | ||
title = editor.getTitle() | ||
@send '/run-code', 'atom', "run_file \"" + fullPath + "\"" | ||
atom.notifications.addSuccess "Saved file and told Sonic Pi to start playing. :)" | ||
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. :)"); | ||
|
||
stop: -> | ||
@send '/stop-all-jobs' | ||
atom.notifications.addInfo "Told Sonic Pi to stop playing." | ||
@send('/stop-all-jobs'); | ||
atom.notifications.addInfo("Told Sonic Pi to stop playing."); | ||
|
||
send: (args...) -> | ||
if atom.config.get('sb-atom-sonic-pi.sendMessagesToGUI') == true | ||
sp_gui = new osc.Client('localhost', 4559) | ||
sp_gui.send args..., -> sp_gui.kill() | ||
sp_server = new osc.Client('127.0.0.1', 4557) | ||
sp_server.send args..., -> sp_server.kill() | ||
sp_gui = new osc.Client('localhost', 4559); | ||
sp_gui.send args..., -> sp_gui.kill(); | ||
sp_server = new osc.Client('127.0.0.1', 4557); | ||
sp_server.send args..., -> sp_server.kill(); | ||
|
||
test_toggle: -> | ||
console.log('sb-atom-sonic-pi was toggled!'); | ||
return ( | ||
if this.modalPanel.isVisible() | ||
console.log('sb-atom-sonic-pi: hiding panel'); | ||
this.modalPanel.hide() | ||
else | ||
console.log('sb-atom-sonic-pi: showing panel'); | ||
this.modalPanel.show() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
sbAtomSonicView = require '../lib/sb-atom-sonic-pi-view' | ||
sbAtomSonicPiView = require '../lib/sb-atom-sonic-pi-view' | ||
|
||
describe "sbAtomSonicView", -> | ||
describe "sbAtomSonicPiView", -> | ||
it "has one valid test", -> | ||
expect("life").toBe "easy" | ||
# I'm not sure why this test is here, but OK... |