0 people like it.

Undertone Baa Baa black sheep

From progfsharp tutorials

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
open Undertone
open Undertone.Waves

let bpm = 90.
let crotchet = Time.noteValue bpm Time.crotchet
let quaver = Time.noteValue bpm Time.quaver

let tune = "C C G G A A AA G F F E E D D C F F F E E D D D C F F F E E E E D D D C C C G G A A AA G F F E E D D C "

let aNote octave length note =
    Creation.makeNote Creation.sine length note octave

let (|Crotchet'|Quaver'|) (str : string) =
    if str.[1] = ' ' then
        Quaver'
    else
        Crotchet'

let LetterToNote (letter : char) =
    printfn "%A" letter
    Note.Parse(typeof<Note>, string letter) :?> Note

let rec tuneToSeq octave str =
    seq {
        match str with
        | Crotchet' ->
            yield! aNote octave crotchet (LetterToNote str.[0])
            let rest =
                str.[3..]
            if String.length rest > 0 then
                yield! tuneToSeq octave rest
        | Quaver' ->
            yield! aNote 4 quaver (LetterToNote str.[0])
            let rest =
                str.[2..]
            if String.length rest > 0 then
                yield! tuneToSeq octave rest }

tuneToSeq 4 tune
|> Player.Play
val bpm : float

Full name: Script.bpm
val crotchet : obj

Full name: Script.crotchet
val quaver : obj

Full name: Script.quaver
val tune : string

Full name: Script.tune
val aNote : octave:'a -> length:'b -> note:'c -> 'd

Full name: Script.aNote
val octave : 'a
val length : 'b
val note : 'c
val str : string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val LetterToNote : letter:char -> 'a

Full name: Script.LetterToNote
val letter : char
Multiple items
val char : value:'T -> char (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.char

--------------------
type char = System.Char

Full name: Microsoft.FSharp.Core.char
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val typeof<'T> : System.Type

Full name: Microsoft.FSharp.Core.Operators.typeof
val tuneToSeq : octave:'a -> str:string -> seq<'b>

Full name: Script.tuneToSeq
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
active recognizer Crotchet': string -> Choice<unit,unit>

Full name: Script.( |Crotchet'|Quaver'| )
val rest : string
module String

from Microsoft.FSharp.Core
val length : str:string -> int

Full name: Microsoft.FSharp.Core.String.length
active recognizer Quaver': string -> Choice<unit,unit>

Full name: Script.( |Crotchet'|Quaver'| )
Raw view New version

More information

Link:http://fssnip.net/kG
Posted:3 years ago
Author:mavnn
Tags: undertone , progfsharp