csounddart 0.0.2 copy "csounddart: ^0.0.2" to clipboard
csounddart: ^0.0.2 copied to clipboard

outdated

Dart interface to Csound API for Web and Desktop.

example/lib/main.dart

import 'package:csounddart/csound.dart';
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:csounddart/csounddart.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }
  
  late Csound _cs;


  static const String _csd =
  """
<CsoundSynthesizer>
<CsOptions>
--output=dac
</CsOptions>
; ==============================================
<CsInstruments>

sr	=	44100
ksmps	=	512
nchnls	=	2
0dbfs	=	1

opcode mtofi,i,i
        imid xin
        iout = 440 * exp(0.0577622645 * (imid - 69))
        xout iout
endop


instr 1	
        inote init p4
        ivel init p5
        ifq = mtofi(inote)
        kfq = k(ifq)
        iT = 1000 / ifq

        aPulse = linseg:a(1, iT/1000, 0)
                aPulse = (aPulse + (noise:a(1,0.5) * aPulse)) / 2

                aPulse = aPulse *  pow(2, ((1-((ivel-1)/126)) * -4 ))
                iff = ivel * 100 + 20
                aPulse = butterlp(aPulse, iff)
  

        ;resonr allows to  clear internal space
                alow, ahigh, ao svfilter aPulse, kfq, 500
  
                //ao = butterbp(aPulse, kfq, 1500)
                amo = ao * 15
                amo -= 3.25
 
                amo = butterlp(amo, 150)
        //ao = lowpass2:a(amo, 150, 50) 
                amo = distort1( amo, 1, 1, 0, 0)
                ; Two parallel lines 
                ;one raising, removing gain, and DC
                a1 = (pow(amo, 2)) * (-0.08)
                a1 = dcblock(a1)

  
                        
                a2 = butterhp(amo, 250) * 0.25
  
                as = limit( ((a1 * 0.0001) + a2 + ao) * 0.7  , -1, 1)
                as = dcblock(as)


        outs as, as


endin

instr 2 
  ao = oscili(0.3, linseg:k(100, p3, 400))
  
  av = vco2(0.3, linseg:k(1, p3, 10))
  chnset(av, "vco")
  ao4 = oscili(1.0, linseg:k(1000, p3, 10))
  chnset(ao4, "sine")
  outs ao,ao
  
endin

instr 3
  ;kfq init 200
  kfq = chnget:k("freq")
  printk 1, kfq
  ao = vco2(0.15, kfq)
  outs ao,ao
endin


instr 4 
  ao = oscili(0.15, 400)
   outs ao,ao
endin
</CsInstruments>
; ==============================================
<CsScore>
i 3 0 100
</CsScore>
</CsoundSynthesizer>


  """;


  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await Csounddart.platformVersion ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  double _sliderFreq = 200;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(

      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Container(
            child: SingleChildScrollView(
              child: Column(
                children: [

                  Text('Running on: $_platformVersion\n'),
                  Container(height: 3,),
                  ElevatedButton(onPressed: () async {
                      _cs = Csound();
                  }, child: Text("Init")),
                  Container(height: 3,),
                  ElevatedButton(onPressed: (){
                    //print(_csd);
                    _cs.compileCsdText(_csd);
                    _cs.perform();
                    _cs.setControlChannel("freq", 200.0);

                  }, child: Text("Play")),
                  Container(height: 3,),
                  ElevatedButton(onPressed: (){
                    _cs.stop();
                    print("Want to stop");

                  }, child: Text("Stop")),
                  Container(height: 5),
                  ElevatedButton(onPressed: (){
                    _cs.readScore("i 4 0 3");

                  }, child: Text("score")),
                  Container(height: 5),
                  Slider(
                    onChanged: (double v)
                    {
                      setState(() {
                        _sliderFreq = v;
                      });
                      _cs.setControlChannel("freq", _sliderFreq  );
                    },
                    value: _sliderFreq,
                    min: 100,
                    max: 500,
                  ),

                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
9
likes
0
pub points
17%
popularity

Publisher

unverified uploader

Dart interface to Csound API for Web and Desktop.

Repository

License

unknown (LICENSE)

Dependencies

ffi, flutter, flutter_web_plugins, js, path

More

Packages that depend on csounddart