How to build midi Tone pattern player in DroidScript

 Midi Tone player 1.0



How to build Midi Tone player build in DroidScript?

Three methods are used here, the first is Note of musical pattern and then second is velocity of tone. At the end method is duration of each tone with in a pattern list.So I can use simulate function to play all pattern listed in app you can make buttons for multi tone for making a instrument player. But commonly this method is use for sound button or gaming objects.For gaming purpose use little games beeps ,but you can try mp3 or wav sounds for games. Please if you found more options to make flixible app try DroidScript built in function labiraries. Thank you good luck.Thanks for all Reader's.
Coding Start here...

//Setup notes in the song.

var HoNotes = [

    "D4","C4","D4","D4","D4","A3",

    "D4","D4","E4","E4","F4","F4","F4","F4","E4",

    "A4","G4","A4","G4","A4","G4","A4","G4","F4","E4"

  ]

//Setup note durations.

var HoDurations = [

    "2n","2n","4n","8n","8n","2n",

    "4n","4n","4n","4n","8n","8n","8n","8n","2n",

    "4n+8n","8n","4n+8n","8n","4n+8n","8n","8n","8n","8n","8n"

  ]

//Setup note velocities.

var HoVelocity = [

    0.9,0.9,0.9,0.7,0.7,0.9,

    0.9,0.7,0.9,0.7,0.9,0.7,0.7,0.7,0.9,

    0.9,0.7,0.9,0.7,0.9,0.7,0.9,0.7,0.7,0.7

  ]

//Other variables.

var length = 25

var note, duration, velocity

var turn = index = 0

//Called when application is started.

function OnStart()

{

	//Create a layout with objects vertically centered.

	lay = app.CreateLayout( "Linear", "VCenter,FillXY" )

	//Add a 'Play' button.

	btn = app.AddButton( lay, "Play", 0.3 )

	btn.SetOnTouch( btn_OnTouch )

	//Add a 'Play' button.

	btnStop= app.AddButton( lay, "Stop", 0.3 )

	btnStop.SetOnTouch( btnStop_OnTouch )

// Text Edit Notes

txt0 = app.AddText( lay,"Notes for Music",1 )

txtEdt = app.AddTextEdit( lay,HoNotes,0.9,0.2)

txtEdt.SetBackColor("#23jjoo");

lay.AddChild( txtEdt )

// Text Edit Velocity

txt1 = app.AddText( lay,"Velocity of Tone",1 )

txtEdt2 = app.AddTextEdit( lay,HoVelocity,0.9,0.2)

txtEdt2.SetBackColor("#33jj33");

lay.AddChild( txtEdt2 )

//Text Edit Duration

txt2 = app.AddText( lay,"Duration of each Tone key",1 )

txtEdt3 = app.AddTextEdit( lay,HoDurations,0.9,0.2)

txtEdt3.SetBackColor("#99jjoo");

lay.AddChild( txtEdt3 )

	//Add layout to app.

	app.AddLayout( lay )

	//Create music component.

    music = app.CreateMusic()

    //Create synthesizer object.

    synth = music.CreateSynth("Synth")

    //Create a transport in repeat mode.

}

function btnStop_OnTouch()

{

synth.StopTone();

}

//Called when user touches our 'Play' button.

function btn_OnTouch()

{

 var   HoNotes= txtEdt.GetText();

  var  HoVelocity = txtEdt2.GetText();

    var HoDurations= txtEdt3.GetText();

    app.SimulateTouch(btn)

    play();

    }

//Play each note.

function play(time)

{

     turn     = index++%length;

    note     = HoNotes[turn]

    duration = HoDurations[turn]

    velocity = HoVelocity[turn]

//synth.PlayTone(note, time, velocity)

synth.PlayStopTone(note, duration, time, velocity)

}

Post a Comment

0 Comments