https://github.com/rodydavis/tonejs_dart
Tone.js api bindings for Dart
https://github.com/rodydavis/tonejs_dart
dart flutter tonejs web
Last synced: about 2 months ago
JSON representation
Tone.js api bindings for Dart
- Host: GitHub
- URL: https://github.com/rodydavis/tonejs_dart
- Owner: rodydavis
- License: other
- Created: 2022-07-27T05:51:28.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-27T06:15:45.000Z (almost 4 years ago)
- Last Synced: 2026-02-01T13:13:56.607Z (5 months ago)
- Topics: dart, flutter, tonejs, web
- Language: Dart
- Homepage: https://rodydavis.github.io/tonejs_dart/
- Size: 5.91 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Tone.js Dart
Tone.js api for Flutter web
## Example
```dart
import 'package:flutter/material.dart';
import 'package:piano/piano.dart';
import 'package:tonejs_dart/tonejs_dart.dart' as Tone;
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Tone.js',
theme: ThemeData.dark(),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
bool started = false;
final synths = [
Tone.Synth(),
Tone.PolySynth(),
Tone.FMSynth(),
Tone.AMSynth(),
];
int idx = 0;
late Tone.Synth synth = synths[idx].toDestination();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Tone.js'),
actions: [
// Pop menu button for synths
DropdownButton(
value: idx,
onChanged: (value) {
if (value == null) {
return;
}
setState(() {
idx = value;
synth = synths[idx].toDestination();
});
},
items: const [
DropdownMenuItem(
value: 0,
child: Text('Mono Synth'),
),
DropdownMenuItem(
value: 1,
child: Text('Poly Synth'),
),
DropdownMenuItem(
value: 2,
child: Text('FM Synth'),
),
DropdownMenuItem(
value: 3,
child: Text('AM Synth'),
),
DropdownMenuItem(
value: 4,
child: Text('Noise Synth'),
),
],
),
],
),
body: InteractivePiano(
highlightedNotes: [NotePosition(note: Note.C, octave: 3)],
naturalColor: Colors.white,
accidentalColor: Colors.black,
keyWidth: 60,
noteRange: NoteRange.forClefs([
Clef.Treble,
]),
onNotePositionTapped: (position) async {
if (!started) {
await Tone.start();
started = true;
}
final noteName = position.name.replaceAll('♯', '#');
synth.triggerAttackRelease(noteName, '8n');
},
),
);
}
}
```