Skip to content

Commit

Permalink
Merge pull request #10 from kindohm/fix-boot-code
Browse files Browse the repository at this point in the history
update boot code to work with Tidal 1.0.11
  • Loading branch information
kindohm authored Apr 18, 2019
2 parents 3d88f60 + 1a57dd0 commit 402b99c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 67 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-tidalcycles",
"displayName": "TidalCycles for VSCode",
"description": "TidalCycles support in VSCode",
"version": "1.0.1",
"version": "1.0.2",
"publisher": "tidalcycles",
"icon": "images/icon128.png",
"repository": "https://github.com/tidalcycles/vscode-tidalcycles",
Expand Down
144 changes: 78 additions & 66 deletions src/tidal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ILogger } from "./logging";
import { IGhci } from "./ghci";
import { ILogger } from './logging';
import { IGhci } from './ghci';
import * as vscode from 'vscode';


/**
* Provides an interface to send instructions to the current Tidal instance.
*/
Expand All @@ -12,11 +11,16 @@ export interface ITidal {

export class Tidal implements ITidal {
tidalBooted: boolean = false;
lineEnding = vscode.workspace.getConfiguration('files', null).get('eol', '\n');
lineEnding = vscode.workspace
.getConfiguration('files', null)
.get('eol', '\n');

constructor(private logger: ILogger, private ghci: IGhci,
private bootTidalPath: string | null, private useBootFileInCurrentDirectory: boolean) {
}
constructor(
private logger: ILogger,
private ghci: IGhci,
private bootTidalPath: string | null,
private useBootFileInCurrentDirectory: boolean
) {}

private async bootTidal(): Promise<boolean> {
if (this.tidalBooted) {
Expand All @@ -34,10 +38,14 @@ export class Tidal implements ITidal {
const folders = vscode.workspace.workspaceFolders;

if (folders !== undefined && folders.length > 0) {
uri = vscode.Uri.parse(`file://${folders[0].uri.path}/BootTidal.hs`);
uri = vscode.Uri.parse(
`file://${folders[0].uri.path}/BootTidal.hs`
);
} else {
this.logger.warning('You must open a folder or workspace in order to use the Tidal \
useBootFileInCurrentDirectory setting.');
this.logger.warning(
'You must open a folder or workspace in order to use the Tidal \
useBootFileInCurrentDirectory setting.'
);
}
} else if (bootTidalPath) {
uri = vscode.Uri.file(`${bootTidalPath}`);
Expand All @@ -61,7 +69,7 @@ export class Tidal implements ITidal {
}

public async sendTidalExpression(expression: string) {
if (!await this.bootTidal()) {
if (!(await this.bootTidal())) {
this.logger.error('Could not boot Tidal');
return;
}
Expand All @@ -74,69 +82,73 @@ export class Tidal implements ITidal {
this.ghci.writeLn(':}');
}

private async getBootCommandsFromFile(uri: vscode.Uri): Promise<string[] | null> {

private async getBootCommandsFromFile(
uri: vscode.Uri
): Promise<string[] | null> {
this.logger.log(`Using Tidal boot file on disk at ${uri.fsPath}`);

let doc: vscode.TextDocument;
try {
doc = await vscode.workspace.openTextDocument(uri);
doc = await vscode.workspace.openTextDocument(uri);
return doc.getText().split(/[\r\n]+/);
} catch (e) {
this.logger.error(`Failed to load boot commands from ${uri.fsPath}`);
return null;
}
}

bootCommands: string[] =
[
':set -XOverloadedStrings',
':set prompt ""',
':set prompt-cont ""',
'import Sound.Tidal.Context',
'tidal <- startTidal (superdirtTarget {oLatency = 0.1, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cFrameTimespan = 1/20})',
'let p = streamReplace tidal',
'let hush = streamHush tidal',
'let list = streamList tidal',
'let mute = streamMute tidal',
'let unmute = streamUnmute tidal',
'let solo = streamSolo tidal',
'let unsolo = streamUnsolo tidal',
'let once = streamOnce tidal False',
'let asap = streamOnce tidal True',
'let nudgeAll = streamNudgeAll tidal',
'let setcps = asap . cps',
'let xfade i = transition tidal (Sound.Tidal.Transition.xfadeIn 4) i',
'let xfadeIn i t = transition tidal (Sound.Tidal.Transition.xfadeIn t) i',
'let histpan i t = transition tidal (Sound.Tidal.Transition.histpan t) i',
'let wait i t = transition tidal (Sound.Tidal.Transition.wait t) i',
'let waitT i f t = transition tidal (Sound.Tidal.Transition.waitT f t) i',
'let jump i = transition tidal (Sound.Tidal.Transition.jump) i',
'let jumpIn i t = transition tidal (Sound.Tidal.Transition.jumpIn t) i',
'let jumpIn\' i t = transition tidal (Sound.Tidal.Transition.jumpIn\' t) i',
'let jumpMod i t = transition tidal (Sound.Tidal.Transition.jumpMod t) i',
'let mortal i lifespan release = transition tidal (Sound.Tidal.Transition.mortal lifespan release) i',
'let interpolate i = transition tidal (Sound.Tidal.Transition.interpolate) i',
'let interpolateIn i t = transition tidal (Sound.Tidal.Transition.interpolateIn t) i',
'let clutch i = transition tidal (Sound.Tidal.Transition.clutch) i',
'let clutchIn i t = transition tidal (Sound.Tidal.Transition.clutchIn t) i',
'let anticipate i = transition tidal (Sound.Tidal.Transition.anticipate) i',
'let anticipateIn i t = transition tidal (Sound.Tidal.Transition.anticipateIn t) i',
'let d1 = p 1',
'let d2 = p 2',
'let d3 = p 3',
'let d4 = p 4',
'let d5 = p 5',
'let d6 = p 6',
'let d7 = p 7',
'let d8 = p 8',
'let d9 = p 9',
'let d10 = p 10',
'let d11 = p 11',
'let d12 = p 12',
'let d13 = p 13',
'let d14 = p 14',
'let d15 = p 15',
'let d16 = p 16',
':set prompt "tidal> "' ];
}
bootCommands: string[] = [
':set -XOverloadedStrings',
':set prompt ""',
':set prompt-cont ""',
'import Sound.Tidal.Context',
'tidal <- startTidal (superdirtTarget {oLatency = 0.1, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cFrameTimespan = 1/20})',
'let p = streamReplace tidal',
'let hush = streamHush tidal',
'let list = streamList tidal',
'let mute = streamMute tidal',
'let unmute = streamUnmute tidal',
'let solo = streamSolo tidal',
'let unsolo = streamUnsolo tidal',
'let once = streamOnce tidal',
'let asap = once',
'let nudgeAll = streamNudgeAll tidal',
'let all = streamAll tidal',
'let resetCycles = streamResetCycles tidal',
'let setcps = asap . cps',
'let xfade i = transition tidal True (Sound.Tidal.Transition.xfadeIn 4) i',
'let xfadeIn i t = transition tidal True (Sound.Tidal.Transition.xfadeIn t) i',
'let histpan i t = transition tidal True (Sound.Tidal.Transition.histpan t) i',
'let wait i t = transition tidal True (Sound.Tidal.Transition.wait t) i',
'let waitT i f t = transition tidal True (Sound.Tidal.Transition.waitT f t) i',
'let jump i = transition tidal True (Sound.Tidal.Transition.jump) i',
'let jumpIn i t = transition tidal True (Sound.Tidal.Transition.jumpIn t) i',
"let jumpIn' i t = transition tidal True (Sound.Tidal.Transition.jumpIn' t) i",
'let jumpMod i t = transition tidal True (Sound.Tidal.Transition.jumpMod t) i',
'let mortal i lifespan release = transition tidal True (Sound.Tidal.Transition.mortal lifespan release) i',
'let interpolate i = transition tidal True (Sound.Tidal.Transition.interpolate) i',
'let interpolateIn i t = transition tidal True (Sound.Tidal.Transition.interpolateIn t) i',
'let clutch i = transition tidal True (Sound.Tidal.Transition.clutch) i',
'let clutchIn i t = transition tidal True (Sound.Tidal.Transition.clutchIn t) i',
'let anticipate i = transition tidal True (Sound.Tidal.Transition.anticipate) i',
'let anticipateIn i t = transition tidal True (Sound.Tidal.Transition.anticipateIn t) i',
'let forId i t = transition tidal False (Sound.Tidal.Transition.mortalOverlay t) i',
'let d1 = p 1',
'let d2 = p 2',
'let d3 = p 3',
'let d4 = p 4',
'let d5 = p 5',
'let d6 = p 6',
'let d7 = p 7',
'let d8 = p 8',
'let d9 = p 9',
'let d10 = p 10',
'let d11 = p 11',
'let d12 = p 12',
'let d13 = p 13',
'let d14 = p 14',
'let d15 = p 15',
'let d16 = p 16',
':set prompt "tidal> "'
];
}

0 comments on commit 402b99c

Please sign in to comment.