Skip to content

Instantly share code, notes, and snippets.

View s3thi's full-sized avatar

Ankur Sethi s3thi

View GitHub Profile
@s3thi
s3thi / app.component.ts
Created January 11, 2016 12:23
sampler.js – click handler
`<button (click)='onClick()' [disabled]='loadingSample'>play</button>`
@s3thi
s3thi / app.component.ts
Created January 11, 2016 11:55
sampler.js – playSample()
playSample() {
let bufferSource = this.audioContext.createBufferSource();
bufferSource.buffer = this.audioBuffer;
bufferSource.connect(this.audioContext.destination);
bufferSource.start(0);
}
@s3thi
s3thi / app.component.ts
Created January 11, 2016 11:49
sampler.js – disable play button while loading a sample (private properties)
export class AppComponent implements OnInit {
private audioContext: AudioContext;
private loadingSample: boolean = false;
private audioBuffer: AudioBuffer;
ngOnInit() {
this.audioContext = new AudioContext();
}
}
@s3thi
s3thi / app.component.ts
Last active January 11, 2016 11:48
sampler.js – disable play button while loading a sample (template)
`<button [disabled]='loadingSample'>play</button>`
@s3thi
s3thi / app.component.ts
Last active January 13, 2016 10:42
sampler.js – load sample in ngOnInit
ngOnInit() {
this.audioContext = new AudioContext();
this.loadingSample = true;
this.fetchSample()
.then((audioBuffer) => {
this.loadingSample = false;
this.audioBuffer = audioBuffer;
})
.catch((error) => {
@s3thi
s3thi / app.component.ts
Created January 11, 2016 09:54
sampler.js – fetchSample()
fetchSample(): Promise<AudioBuffer> {
return fetch(‘samples/snare.wav’)
.then((response) => response.arrayBuffer())
.then((buffer) => {
return new Promise((resolve, reject) => {
this.audioContext.decodeAudioData(buffer, resolve, reject);
});
});
}
@s3thi
s3thi / app.component.ts
Last active January 11, 2016 12:05
sampler.js – initialize audio context
import { Component, OnInit } from ‘angular2/core’;
@Component({
selector: 'my-app',
template: `<h1>My First Angular2 App</h1>`
})
export class AppComponent implements OnInit {
private audioContext: AudioContext;
@s3thi
s3thi / app.component.ts
Last active January 11, 2016 11:40
sampler.js – initial component
import { Component } from ‘angular2/core’;
@Component({
 selector: ‘my-app’,
 template: `<h1>My First Angular 2 App</h1>`
})
export class AppComponent { }
def add_five(n):
return n+5
def add_seven(n):
return n+7
def add_nine(n):
return n+9
def fail():
return 'this will break