SaveText.Ru

Без имени
  1. //This sample demonstrates all available
  2. //functionality of the Software Synthesizer.
  3. //(This sample can be useful for creating game sounds)
  4.  
  5. //Init some variables.
  6. var minFreq = 200;
  7. var maxFreq = 2000;
  8. var freq = 1100;
  9.  
  10. //Called when application is started.
  11. function OnStart()
  12. {
  13.         //Lock screen orientation to Portrait.
  14.         app.SetOrientation( "Portrait" );
  15.  
  16.         //Create main layout that fills the screen.
  17.         lay = app.CreateLayout( "Linear", "FillXY,VCenter" );
  18.  
  19.         //Create wave shape toggle buttons.
  20.         layShape = app.CreateLayout( "Linear", "Horizontal" );
  21.         layShape.SetBackColor("#ff303030");
  22.         layShape.SetPadding( 0,0.01,0,0 );
  23.         layShape.SetSize( 0.9 );
  24.         lay.AddChild( layShape );
  25.         togSin = app.CreateToggle( "Sin", 0.2, 0.08 );
  26.         togSin.SetOnTouch( tog_OnTouch );
  27.         layShape.AddChild( togSin );
  28.         togSaw = app.CreateToggle( "Saw", 0.2, 0.08 );
  29.         togSaw.SetChecked( true );
  30.         togSaw.SetOnTouch( tog_OnTouch );
  31.         layShape.AddChild( togSaw );
  32.         togSqu = app.CreateToggle( "Square", 0.2, 0.08 );
  33.         togSqu.SetOnTouch( tog_OnTouch );
  34.         layShape.AddChild( togSqu );
  35.         togWht = app.CreateToggle( "White", 0.2, 0.08 );
  36.         togWht.SetOnTouch( tog_OnTouch );
  37.         layShape.AddChild( togWht );
  38.  
  39.         //Create tabs.
  40.         tabs = app.CreateTabs( "VCA,VCF,PHASER,DELAY", 0.9, 0.68, "" );
  41.         tabs.SetMargins( 0,0.01,0,0 );
  42.         lay.AddChild( tabs );    
  43.  
  44.         //Create VCA controls.
  45.         layVca = tabs.GetLayout( "VCA" );
  46.         CreateVCAControls();
  47.  
  48.         //Create VCF controls.
  49.         layVcf = tabs.GetLayout( "VCF" );
  50.         CreateVCFControls();
  51.  
  52.         //Create Phaser controls.
  53.         layPha = tabs.GetLayout( "PHASER" );
  54.         layVca.AddChild( layPha );
  55.         CreatePhaserControls();
  56.  
  57.          //Create Delay controls.
  58.         layDel = tabs.GetLayout( "DELAY" );
  59.         layVca.AddChild( layDel );
  60.         CreateDelayControls();
  61.  
  62.         //Create layout for buttons and freqency slider.
  63.         layBtn = app.CreateLayout( "Linear", "Vertical" );
  64.         layBtn.SetBackColor("#ff303030");
  65.         layBtn.SetSize( 0.9 );
  66.         layBtn.SetMargins( 0, 0.01, 0, 0 );
  67.         layBtn.SetPadding( 0, 0.01, 0, 0.01 );
  68.         lay.AddChild( layBtn );
  69.  
  70.         //Create 'Play' imag/button.
  71.         imgPlay = app.CreateImage( null, 0.4, 0.08 );
  72.         imgPlay.SetColor( "#ffffff" );
  73.         imgPlay.SetPaintColor( "#ff000000" );
  74.         imgPlay.SetTextSize( 22 );
  75.         imgPlay.DrawText( "Play", 0.35, 0.6 );
  76.         imgPlay.SetOnTouchDown( imgPlay_OnTouchDown );
  77.         imgPlay.SetOnTouchUp( imgPlay_OnTouchUp );
  78.         layBtn.AddChild( imgPlay );
  79.  
  80.         //Create 'Frequency' text label.
  81.         txtFreq = app.CreateText( "Frequency" );
  82.         //txtFreq.SetMargins( 0, 0.05, 0, 0 );
  83.         layBtn.AddChild( txtFreq );
  84.  
  85.         //Create frequency seek bar.
  86.         skbFreq = app.CreateSeekBar( 0.8, -1 );
  87.         skbFreq.SetRange( 1.0 );
  88.         skbFreq.SetValue( 0.5 );
  89.         skbFreq.SetOnTouch( skbFreq_OnTouch );
  90.         layBtn.AddChild( skbFreq );
  91.  
  92.         //Add main layout to app.
  93.         app.AddLayout( lay );
  94.  
  95.         //Create Synth object and set initial vals.
  96.         synth1 = app.CreateSynth();
  97.         synth1.SetWaveShape( "Saw" );
  98.         synth1.SetVolume( 1.0, 1.0 );
  99.  
  100.         //Update synth to reflect initial slider positions.
  101.         skbFreq_OnTouch( skbFreq.GetValue() );
  102.         skbVcaAttack_OnTouch( skbVcaAttack.GetValue() );
  103.         skbVcaDecay_OnTouch( skbVcaDecay.GetValue() );
  104.         skbVcaSustain_OnTouch( skbVcaSustain.GetValue() );
  105.         skbVcaRelease_OnTouch( skbVcaRelease.GetValue() );
  106.         skbVcfAttack_OnTouch( skbVcfAttack.GetValue() );
  107.         skbVcfDecay_OnTouch( skbVcfDecay.GetValue() );
  108.         skbVcfSustain_OnTouch( skbVcfSustain.GetValue() );
  109.         skbVcfRelease_OnTouch( skbVcfRelease.GetValue() );
  110.         skbVcfCutoff_OnTouch( skbVcfCutoff.GetValue() );
  111.         skbVcfResonance_OnTouch( skbVcfResonance.GetValue() );
  112.         skbDryWet_OnTouch( skbDryWet.GetValue() );
  113.         skbSweepRate_OnTouch( skbSweepRate.GetValue() );
  114.         skbSweepRange_OnTouch( skbSweepRange.GetValue() );
  115.         skbPhaserFeedback_OnTouch( skbPhaserFeedback.GetValue() );
  116.         skbDelay_OnTouch( skbDelay.GetValue() );
  117.         skbFeedback_OnTouch( skbFeedback.GetValue() );
  118. }
  119.  
  120. //Create the VCA controls.
  121. function CreateVCAControls()
  122. {
  123.         //Create VCA attack controls.
  124.         txtVcaAttack = app.CreateText( "VCA Attack" );
  125.         txtVcaAttack.SetMargins(0,0.02,0,0);
  126.         layVca.AddChild( txtVcaAttack );
  127.         skbVcaAttack = app.CreateSeekBar( 0.7, -1 );
  128.         skbVcaAttack.SetOnTouch( skbVcaAttack_OnTouch );
  129.         skbVcaAttack.SetRange( 1000 );
  130.         skbVcaAttack.SetValue( 10 );
  131.         layVca.AddChild( skbVcaAttack );
  132.  
  133.         //Create VCA decay controls.
  134.         txtVcaDecay = app.CreateText( "VCA Decay" );
  135.         layVca.AddChild( txtVcaDecay );
  136.         skbVcaDecay = app.CreateSeekBar( 0.7, -1 );
  137.         skbVcaDecay.SetOnTouch( skbVcaDecay_OnTouch );
  138.         skbVcaDecay.SetRange( 1000 );
  139.         skbVcaDecay.SetValue( 500 );
  140.         layVca.AddChild( skbVcaDecay );
  141.  
  142.         //Create VCA sustain controls.
  143.         txtVcaSustain = app.CreateText( "VCA Sustain" );
  144.         layVca.AddChild( txtVcaSustain );
  145.         skbVcaSustain = app.CreateSeekBar( 0.7, -1 );
  146.         skbVcaSustain.SetOnTouch( skbVcaSustain_OnTouch );
  147.         skbVcaSustain.SetRange( 1.0 );
  148.         skbVcaSustain.SetValue( 0.5 );
  149.         layVca.AddChild( skbVcaSustain );
  150.  
  151.         //Create VCA release controls.
  152.         txtVcaRelease = app.CreateText( "VCA Release" );
  153.         layVca.AddChild( txtVcaRelease );
  154.         skbVcaRelease = app.CreateSeekBar( 0.7, -1 );
  155.         skbVcaRelease.SetOnTouch( skbVcaRelease_OnTouch );
  156.         skbVcaRelease.SetRange( 1000 );
  157.         skbVcaRelease.SetValue( 500 );
  158.         layVca.AddChild( skbVcaRelease );
  159. }
  160.  
  161. //Create the VCF controls.
  162. function CreateVCFControls()
  163. {
  164.         //Create 'Enable' check box.
  165.         chkVcf = app.CreateCheckBox( "" );
  166.         chkVcf.SetMargins( 0,0.01,0,0 );
  167.         chkVcf.SetOnTouch( chkVcf_OnTouch );
  168.         layVcf.AddChild( chkVcf );
  169.  
  170.         //Create VCF attack controls.
  171.         txtVcfAttack = app.CreateText( "VCF Attack" );
  172.         layVcf.AddChild( txtVcfAttack );
  173.         skbVcfAttack = app.CreateSeekBar( 0.7, -1 );
  174.         skbVcfAttack.SetOnTouch( skbVcfAttack_OnTouch );
  175.         skbVcfAttack.SetRange( 1000 );
  176.         skbVcfAttack.SetValue( 200 );
  177.         layVcf.AddChild( skbVcfAttack );
  178.  
  179.         //Create VCF decay controls.
  180.         txtVcfDecay = app.CreateText( "VCF Decay" );
  181.         layVcf.AddChild( txtVcfDecay );
  182.         skbVcfDecay = app.CreateSeekBar( 0.7, -1 );
  183.         skbVcfDecay.SetOnTouch( skbVcfDecay_OnTouch );
  184.         skbVcfDecay.SetRange( 1000 );
  185.         skbVcfDecay.SetValue( 500 );
  186.         layVcf.AddChild( skbVcfDecay );
  187.  
  188.         //Create VCF sustain controls.
  189.         txtVcfSustain = app.CreateText( "VCF Sustain" );
  190.         layVcf.AddChild( txtVcfSustain );
  191.         skbVcfSustain = app.CreateSeekBar( 0.7, -1 );
  192.         skbVcfSustain.SetOnTouch( skbVcfSustain_OnTouch );
  193.         skbVcfSustain.SetRange( 1.0 );
  194.         skbVcfSustain.SetValue( 0.5 );
  195.         layVcf.AddChild( skbVcfSustain );
  196.  
  197.         //Create VCF release controls.
  198.         txtVcfRelease = app.CreateText( "VCF Release" );
  199.         layVcf.AddChild( txtVcfRelease );
  200.         skbVcfRelease = app.CreateSeekBar( 0.7, -1 );
  201.         skbVcfRelease.SetOnTouch( skbVcfRelease_OnTouch );
  202.         skbVcfRelease.SetRange( 1000 );
  203.         skbVcfRelease.SetValue( 500 );
  204.         layVcf.AddChild( skbVcfRelease );
  205.  
  206.         //Create VCF cutoff controls.
  207.         txtVcfCutoff = app.CreateText( "VCF Cutoff" );
  208.         layVcf.AddChild( txtVcfCutoff );
  209.         skbVcfCutoff = app.CreateSeekBar( 0.7, -1 );
  210.         skbVcfCutoff.SetOnTouch( skbVcfCutoff_OnTouch );
  211.         skbVcfCutoff.SetRange( 2000 );
  212.         skbVcfCutoff.SetValue( 1500 );
  213.         layVcf.AddChild( skbVcfCutoff );
  214.  
  215.         //Create VCF resonance controls.
  216.         txtVcfResonance = app.CreateText( "VCF Resonance" );
  217.         layVcf.AddChild( txtVcfResonance);
  218.         skbVcfResonance = app.CreateSeekBar( 0.7, -1 );
  219.         skbVcfResonance.SetOnTouch( skbVcfResonance_OnTouch );
  220.         skbVcfResonance.SetRange( 1.0 );
  221.         skbVcfResonance.SetValue( 0.75 );
  222.         layVcf.AddChild( skbVcfResonance );
  223. }
  224.  
  225. //Create Phaser controls.
  226. function CreatePhaserControls()
  227. {
  228.         //Create 'Enable' check box.
  229.         chkPhaser = app.CreateCheckBox( "" );
  230.         chkPhaser.SetMargins( 0,0.01,0,0 );
  231.         chkPhaser.SetOnTouch( chkPhaser_OnTouch );
  232.         layPha.AddChild( chkPhaser );
  233.  
  234.         //Create Dry/Wet controls.
  235.         txtDryWet = app.CreateText( "Dry/Wet" );
  236.         layPha.AddChild( txtDryWet );
  237.         skbDryWet = app.CreateSeekBar( 0.7, -1 );
  238.         skbDryWet.SetOnTouch( skbDryWet_OnTouch );
  239.         skbDryWet.SetRange( 1.0 );
  240.         skbDryWet.SetValue( 0.5 );
  241.         layPha.AddChild( skbDryWet );
  242.  
  243.         //Create Sweep rate controls.
  244.         txtSweepRate = app.CreateText( "Sweep Rate" );
  245.         layPha.AddChild( txtSweepRate );
  246.         skbSweepRate = app.CreateSeekBar( 0.7, -1 );
  247.         skbSweepRate.SetOnTouch( skbSweepRate_OnTouch );
  248.         skbSweepRate.SetRange( 5.0 );
  249.         skbSweepRate.SetValue( 2.0 );
  250.         layPha.AddChild( skbSweepRate );
  251.  
  252.         //Create Sweep range controls.
  253.         txtSweepRange = app.CreateText( "Sweep Range" );
  254.         layPha.AddChild( txtSweepRange );
  255.         skbSweepRange = app.CreateSeekBar( 0.7, -1 );
  256.         skbSweepRange.SetOnTouch( skbSweepRange_OnTouch );
  257.         skbSweepRange.SetRange( 7.0 );
  258.         skbSweepRange.SetValue( 5.0 );
  259.         layPha.AddChild( skbSweepRange );
  260.  
  261.         //Ceate Feedback controls.
  262.         txtPhaserFeedback = app.CreateText( "Feedback" );
  263.         layPha.AddChild( txtPhaserFeedback);
  264.         skbPhaserFeedback = app.CreateSeekBar( 0.7, -1 );
  265.         skbPhaserFeedback.SetOnTouch( skbPhaserFeedback_OnTouch );
  266.         skbPhaserFeedback.SetRange( 0.5 );
  267.         skbPhaserFeedback.SetValue( 0.1 );
  268.         layPha.AddChild( skbPhaserFeedback );
  269. }
  270.  
  271. //Create delay controls.
  272. function CreateDelayControls()
  273. {
  274.         //Create 'Enable' check box.
  275.         chkDelay = app.CreateCheckBox( "" );
  276.         chkDelay.SetMargins( 0,0.01,0,0 );
  277.         chkDelay.SetOnTouch( chkDelay_OnTouch );
  278.         layDel.AddChild( chkDelay );
  279.  
  280.         //Create Delay controls.
  281.         txtDelay = app.CreateText( "Delay" );
  282.         layDel.AddChild( txtDelay );
  283.         skbDelay = app.CreateSeekBar( 0.7, -1 );
  284.         skbDelay.SetOnTouch( skbDelay_OnTouch );
  285.         skbDelay.SetRange( 1000 );
  286.         skbDelay.SetValue( 40 );
  287.         layDel.AddChild( skbDelay );
  288.  
  289.         //Create feedback controls.
  290.         txtFeedback = app.CreateText( "Feedback" );
  291.         layDel.AddChild( txtFeedback);
  292.         skbFeedback = app.CreateSeekBar( 0.7, -1 );
  293.         skbFeedback.SetOnTouch( skbFeedback_OnTouch );
  294.         skbFeedback.SetRange( 1.0 );
  295.         skbFeedback.SetValue( 0.1 );
  296.         layDel.AddChild( skbFeedback );
  297. }
  298.  
  299. //Handle wave shape select.
  300. function tog_OnTouch()
  301. {
  302.         //Clear all toggles.
  303.         togSin.SetChecked( false );
  304.         togSaw.SetChecked( false );
  305.         togSqu.SetChecked( false );
  306.         togWht.SetChecked( false );
  307.  
  308.         //Set chosen toggle and set wave shape.
  309.         var tog = app.GetLastToggle();
  310.         tog.SetChecked( true );
  311.         synth1.SetWaveShape( tog.GetText() );
  312. }
  313.  
  314. //Handle 'Play' button down.
  315. function imgPlay_OnTouchDown()
  316. {
  317.         synth1.PlayTone( freq, 2000 );
  318.         imgPlay.SetAlpha( 0.7 );
  319. }
  320.  
  321. //Handle 'Play' button up.
  322. function imgPlay_OnTouchUp()
  323. {
  324.         imgPlay.SetAlpha( 1.0 );
  325. }
  326.  
  327. //Handle 'Stop' button.
  328. function btnStop_OnTouch()
  329. {
  330.         synth2.PlayTone( freq+440, 2000 );
  331. }
  332.  
  333. //Called when user changes frequency.
  334. function skbFreq_OnTouch( val )
  335. {
  336.         freq = minFreq + (maxFreq - minFreq) * val;
  337.         synth1.SetFrequency( freq );
  338.  
  339.         txtFreq.SetText( "Frequency " + Math.round(freq) + "Hz" );
  340. }
  341.  
  342.  
  343. //Called when user touches VCA attack bar.
  344. function skbVcaAttack_OnTouch( val )
  345. {
  346.         txtVcaAttack.SetText( "VCA Attack "+val+"ms" );
  347.         synth1.SetVcaAttack( val );
  348. }
  349.  
  350. //Called when user touches VCA decay bar.
  351. function skbVcaDecay_OnTouch( val )
  352. {
  353.         txtVcaDecay.SetText( "VCA Decay "+val+"ms" );
  354.         synth1.SetVcaDecay( val );
  355. }
  356.  
  357. //Called when user touches VCA sustain bar.
  358. function skbVcaSustain_OnTouch( val )
  359. {
  360.         txtVcaSustain.SetText( "VCA Sustain "+val );
  361.         synth1.SetVcaSustain( val );
  362. }
  363.  
  364. //Called when user touches VCA release bar.
  365. function skbVcaRelease_OnTouch( val )
  366. {
  367.         txtVcaRelease.SetText( "VCA Release "+val+"ms" );
  368.         synth1.SetVcaRelease( val );
  369. }
  370.  
  371. //Called when user enables/disables VCF.
  372. function chkVcf_OnTouch( val )
  373. {
  374.         synth1.SetVcfEnabled( val );
  375. }
  376.  
  377. //Called when user touches VCF attack bar.
  378. function skbVcfAttack_OnTouch( val )
  379. {
  380.         txtVcfAttack.SetText( "VCF Attack "+val+"ms" );
  381.         synth1.SetVcfAttack( val );
  382. }
  383.  
  384. //Called when user touches VCF decay bar.
  385. function skbVcfDecay_OnTouch( val )
  386. {
  387.         txtVcfDecay.SetText( "VCF Decay "+val+"ms" );
  388.         synth1.SetVcfDecay( val );
  389. }
  390.  
  391. //Called when user touches VCF sustain bar.
  392. function skbVcfSustain_OnTouch( val )
  393. {
  394.         txtVcfSustain.SetText( "VCF Sustain "+val );
  395.         synth1.SetVcfSustain( val );
  396. }
  397.  
  398. //Called when user touches VCF release bar.
  399. function skbVcfRelease_OnTouch( val )
  400. {
  401.         txtVcfRelease.SetText( "VCF Release "+val+"ms" );
  402.         synth1.SetVcfRelease( val );
  403. }
  404.  
  405. //Called when user touches VCF cutoff bar.
  406. function skbVcfCutoff_OnTouch( val )
  407. {
  408.         txtVcfCutoff.SetText( "VCF Cutoff "+val+"Hz" );
  409.         synth1.SetVcfCutoff( val );
  410. }
  411.  
  412. //Called when user touches VCF sustain bar.
  413. function skbVcfResonance_OnTouch( val )
  414. {
  415.         txtVcfResonance.SetText( "VCF Resonance "+val );
  416.         synth1.SetVcfResonance( val );
  417. }
  418.  
  419. //Called when user enables/disables Phaser.
  420. function chkPhaser_OnTouch( val )
  421. {
  422.         synth1.SetPhaserEnabled( val );
  423. }
  424.  
  425. //Called when user changes Phaser Dry/Wet.
  426. function skbDryWet_OnTouch( val )
  427. {
  428.         txtDryWet.SetText( "Dry/Wet "+val );
  429.         synth1.SetPhaserDryWet( val );
  430. }
  431.  
  432. //Called when user changes Phaser Sweep Rate.
  433. function skbSweepRate_OnTouch( val )
  434. {
  435.         txtSweepRate.SetText( "Sweep Rate "+val );
  436.         synth1.SetPhaserRate( val );
  437. }
  438.  
  439. //Called when user changes Phaser Sweep Range.
  440. function skbSweepRange_OnTouch( val )
  441. {
  442.         txtSweepRange.SetText( "Sweep Range "+val );
  443.         synth1.SetPhaserRange( val );
  444. }
  445.  
  446. //Called when user changes Phaser Feedback.
  447. function skbPhaserFeedback_OnTouch( val )
  448. {
  449.         txtPhaserFeedback.SetText( "Sweep Feedback "+val );
  450.         synth1.SetPhaserFeedback( val );
  451. }
  452.  
  453. //Called when user enables/disables Delay.
  454. function chkDelay_OnTouch( val )
  455. {
  456.         synth1.SetDelayEnabled( val );
  457. }
  458.  
  459. //Called when user touches Delay bar.
  460. function skbDelay_OnTouch( val )
  461. {
  462.         txtDelay.SetText( "Delay "+val );
  463.         synth1.SetDelay( val );
  464. }
  465.  
  466. //Called when user touches Delay Feedback bar.
  467. function skbFeedback_OnTouch( val )
  468. {
  469.         txtFeedback.SetText( "Feedback "+val );
  470.         synth1.SetFeedback( val );
  471. }
  472.  

Share with your friends:

Распечатать