亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

ChucK初步(4)

2019-11-14 09:04:39
字體:
來源:轉載
供稿:網友

arrays

declaringmulti-dimensionallookupassociative arraysassignment

Arrays

This sections specifies(指定) how arrays are declared and used in ChucK. Some quick notes: * arrays can be indexed by integer(整數) (0-indexed). * any array can also be used as an associative(聯想的) map, indexed by strings. * it is important to note that the integer-indexed portion(部分) and the associative portion of an array are stored in separate namespaces * arrays are objects, and will behave similarly under reference assignment(引用賦值) and other Operations common to objects.

declaration

Arrays(數組) can be declared in the following way:

// declare 10 element array of int, called fooint foo[10];// since array of int (PRimitive type), the contents// are automatically initialized to 0

Arrays can also be initialized(初始化):

// chuck intializer(初始化器,程序) to array reference[ 1, 1, 2, 3, 5, 8 ] @=> int foo[];

In the above code, there are several things to note: * initializers must contain the same or similar types. the compiler(編譯器) will attempt to find the highest common base type of all the elements(元素). if no such common element is found, an error is reported. * the type of the initializer [ 1, 1, 2, 3, 5, 8 ] is int[]. the intializer is an array that can be used directly when arrays are expected. * the at-chuck operator (@=>) means assignment(分配), and is discussed at length(詳細地) in operators and operations. * int foo[] is declaring an empty reference(引用) to an array(數組). the statement(聲明) assigns(分配) the initializer array to foo. * arrays are objects.

When declaring an array of objects, the objects inside the array are automatically(自動的) instantiated(實例化).

// objects in arrays are automatically instantiatedObject group[10];

If you only want an array of object references:(對象引用數組)

// array of null object referencesObject @ group[10];

Check here more information on object declaration and instantation in Chuck.

The above examples are 1-dimensional arrays (or vectors(矢量)).

multi-dimensional arrays

It is possible (and equally easy) to declare multi-dimensional arrays:

// declare 4 by 6 by 8 array of floatfloat foo3D[4][6][8];//和C還是很像

Initializers work in similar ways:

// declare 2 by 2 array of int[ [1,3], [2,4] ] @=> int bar[][];

In the above code, note the two [][] since we make a matrix.

lookup

Elements in an array can be accessed using [] /(in the appropriate quantities).

// declare an array of floats[ 3.2, 5.0, 7 ] @=> float foo[];// access the 0th element (debug print)<<< foo[0] >>>; // hopefully 3.2// set the 2nd element8.5 => foo[2];

Looping over the elements of an array:

// array of floats again[ 1, 2, 3, 4, 5, 6 ] @=> int foo[];//官方的例子這里是float,但是實際測試,整型不可以被分配到float里。// loop over the entire arrayfor( 0 => int i; i < foo.cap(); i++ )//foo.cap(){ // do something (debug print) <<< foo[i] >>>;//自帶換行}

Accessing multi-dimensional array:

// 2D arrayint foo[4][4];// set an element10 => foo[2][2];

If the index exceeds(超過) the bounds of the array in any dimension(標出尺寸), an exception(異常) is issued(被放出) and the current shred(片段) is halted(停止).

// array capacity is 5int foo[5];// this should cause ArrayOutOfBoundsException// access element 6 (index 5)<<< foo[5] >>>;

a longer program: otf_06.ck from examples:

// the period.5::second => dur T;// synchronize to period (for on-the-fly(運行中) synchronization)T - (now % T) => now;// our patchSinOsc s => JCRev r => dac;//JCRev是指什么類型?// initialize.05 => s.gain;.25 => r.mix;// scale (pentatonic(五音階的); in semitones(半音程))[ 0, 2, 4, 7, 9 ] @=> int scale[];// infinite time loopwhile( true ){ // pick something from the scale scale[ Math.rand2(0,4) ] => float freq; // get the final freq Std.mtof( 69 + (Std.rand2(0,3)*12 + freq) ) => s.freq; // reset phase for extra bandwidth(為額外帶寬重置相位) 0 => s.phase; // advance time if( Std.randf() > -.5 ) .25::T => now; else .5::T => now;}

associative arrays(關聯數組)

(類似于python中的字典,用字符串索引)

Any array(數組) can be used also as an associative array, indexed on strings. Once the regular array is instantiated, no further work has to be done to make it associative as well - just start using it as such.

// declare regular array(正規數組) (capacity(容量) doesn't matter so much)float foo[4];// use as int-based array2.5 => foo[0];// use as associative array4.0 => foo["yoyo"];// access as associative (print)<<< foo["yoyo"] >>>;// access empty element<<< foo["gaga"] >>>; // -> should print 0.0

It is important to note (again), that the address space of the integer(整數) portion(部分) and the associative portion of the array are completely separate. For example:

// declare arrayint foo[2];// put something in element 010 => foo[0];// put something in element "0"20 => foo["0"];// this should print out 10 20<<< foo[0], foo["0"] >>>;

The capacity(容量) of an array relates only to the integer portion of it. An array with an integer portion of capacity 0, for example, can still have any number of associative indexes.

// declare array of 0 capacityint foo[0];// put something in element "here"20 => foo["here"];// this should print out 20<<< foo["here"] >>>// this should cause an exception<<< foo[0] >>>

Note: The associative capacity of an array is not defined(定義), so objects used in the associative namespace must be explicitly(明確的) instantiated, in contrast(對比) to those in the integer namespace (此處不甚明白)

Accessing an uninstantiated element(元素) of the associate array will return a null reference. Please check the class documentation page for an explanation of ChucK objects and references.

class Item { float weight; }Item box[10]; // integer indices(指數;目錄(index的復數)) ( up to capacity ) are pre-instantiated.1.2 => box[1].weight; // instantiate element "lamp";new Item @=> box["lamp"]; // access allowed to "lamp"2.0 => box["lamp"].weight; // access causes a `NullPointerException` 2.0 => box["sweater"].weight;

array assignment

Arrays are objects. So when we declare an array, we are actually

(1) declaring a reference to array (reference variable(引用變量))(2) instantiating a new array and reference assigned(分配) to the variable.

A (null) reference is a reference variable that points to no object or null. A null reference to an array can be created in this fashion:

// declare array reference (by not specifying(指定) a capacity)int foo[];// we can now assign any int[] to foo[ 1, 2, 3 ] @=> foo;// print out 0th element<<< foo[0] >>>;

This is also useful in declaring functions that have arrays(數組) as arguments or return type.

// our functionfun void print( int bar[] ){ // print it for( 0 => int i; i < bar.cap(); i++ ) <<< bar[0] >>>;}// we can call the function with a literalprint( [ 1, 2, 3, 4, 5 ] );// or can we can pass a reference variableint foo[10];print( foo );

Like other objects, it is possible make multiple references(多個引用) to a single array. Like other objects, all assignments(分配) are reference assignments, meaning the contents are NOT copied, only a reference to array is duplicated(被復制).(傳遞引用)

// our single arrayint the_array[10];// assign reference to foo and barthe_array => int foo[] => int bar[];// (the_array, foo, and bar now all reference the same array)// we change the_array and print foo...// they reference the same array, changing one is like changing the other// 連鎖反應,內存中的存儲信息改變了5 => the_array[0];<<< foo[0] >>>; // should be 5

It is possible to reference sub-sections(小節) of multi-dimensional(多維) arrays.

// a 3D arrayint foo3D[4][4][4];// we can make a reference to a sub-sectionfoo3D[2] => int bar[][];// (note that the dimensions must add up!)
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
97精品国产97久久久久久| 国语自产精品视频在线看一大j8| 日本一区二区在线免费播放| 久久大大胆人体| 欧美激情视频在线免费观看 欧美视频免费一| 亚洲国产成人一区| 亚洲成人黄色在线| 亚洲男人天堂2023| 欧美肥臀大乳一区二区免费视频| 亚洲美女精品成人在线视频| 久久人人爽人人爽人人片av高请| 亚洲免费小视频| 久久综合久久美利坚合众国| 久久精品国产欧美激情| 国产91精品久久久久久久| 性金发美女69hd大尺寸| 狠狠躁天天躁日日躁欧美| 69久久夜色精品国产69乱青草| 91精品国产91久久久久久最新| 国产欧美日韩精品在线观看| 97精品久久久中文字幕免费| 国产精品国产自产拍高清av水多| 国产成人精品免费久久久久| 久久亚洲一区二区三区四区五区高| 亚洲全黄一级网站| 日韩禁在线播放| 亚洲日本aⅴ片在线观看香蕉| 久久在线视频在线| 亚洲缚视频在线观看| 久久天天躁狠狠躁夜夜爽蜜月| 国产精品aaaa| 欧美第一黄色网| 国产极品精品在线观看| www.欧美精品| 亚洲欧美日韩区| 久久久久这里只有精品| 亚洲精品白浆高清久久久久久| 亚洲精品自拍第一页| 国产在线精品播放| 国内精品久久影院| 国产精品女主播| 亚洲男人天堂古典| 日韩欧美一区二区在线| 亚洲性线免费观看视频成熟| 国产剧情日韩欧美| 大荫蒂欧美视频另类xxxx| 日韩视频一区在线| 久久精品视频在线| 亚洲日韩欧美视频一区| 国产成人一区二区三区电影| 国产精品欧美一区二区| 91精品久久久久久久久中文字幕| 亚洲人成人99网站| 国产一区二区三区在线看| 亚洲性生活视频| 欧美激情视频一区| 中文字幕久热精品视频在线| 久久久国产精品一区| 精品视频久久久久久| 亚洲综合在线中文字幕| 国产视频久久久| 久久久99久久精品女同性| 亚洲色图激情小说| 911国产网站尤物在线观看| 久久久国产精品一区| 亚洲免费人成在线视频观看| 亚洲高清福利视频| 亚洲精品国产综合区久久久久久久| 亚洲成人av片在线观看| 亚洲国产天堂久久综合| 日韩美女在线播放| 中文字幕无线精品亚洲乱码一区| 欧美最顶级丰满的aⅴ艳星| 中文日韩电影网站| 国产精品亚洲视频在线观看| 国产精品99久久久久久www| 久久不射热爱视频精品| 欧美亚洲国产视频小说| 欧美日韩亚洲高清| 亚洲国产精品美女| 国产精品香蕉国产| 亚洲人av在线影院| 在线观看欧美日韩国产| 欧美成人免费在线观看| 狠狠色狠狠色综合日日五| 日韩成人在线视频网站| 国产午夜精品久久久| 在线播放国产一区中文字幕剧情欧美| 国产一区二区视频在线观看| 国产一区二区在线免费视频| 欧美性jizz18性欧美| 国产精品自产拍在线观| 8050国产精品久久久久久| 奇米影视亚洲狠狠色| 91性高湖久久久久久久久_久久99| 欧美一区二区影院| 韩剧1988在线观看免费完整版| 2019国产精品自在线拍国产不卡| 久久久久久久久久久久久久久久久久av| 欧美人与物videos| 国产va免费精品高清在线观看| 亚洲一区二区三区在线视频| 91精品久久久久久久久久入口| 97在线观看免费高清| 日韩三级影视基地| 亚洲人成电影网站色xx| 欧美在线视频在线播放完整版免费观看| 亚洲性69xxxbbb| 亚洲成人免费网站| 欧美中文在线视频| 亚洲在线一区二区| 欧美日韩国产中文精品字幕自在自线| 国产精品嫩草影院久久久| 色偷偷888欧美精品久久久| 国产精品视频导航| 亚洲性日韩精品一区二区| 国产suv精品一区二区三区88区| 欧美有码在线观看| 精品在线观看国产| 国产免费亚洲高清| 久久国产精品久久国产精品| 成人欧美一区二区三区黑人孕妇| 久久综合电影一区| 欧美成人黑人xx视频免费观看| 疯狂做受xxxx高潮欧美日本| 欧美性猛交xxx| 日韩电影在线观看中文字幕| 91精品国产综合久久香蕉最新版| 日韩在线视频播放| 成人国产在线激情| 亚洲一区二区少妇| 97在线观看免费| 精品久久久久久久久久ntr影视| 成人免费在线视频网址| 91在线看www| 久久久久久亚洲精品不卡| 欧美激情国产日韩精品一区18| 国产精品久久久久久久久久东京| 国产精品27p| 亚洲欧美日韩爽爽影院| 欧美在线激情网| 午夜精品蜜臀一区二区三区免费| 欧美理论片在线观看| 国产精品爽爽爽| 欧美性xxxxx| 国产精品99久久久久久人| 91免费版网站入口| 久久精视频免费在线久久完整在线看| 日韩av最新在线| 亚洲在线免费视频| 精品久久久国产精品999| 欧美视频中文字幕在线| 欧美一级在线播放| 国产欧美精品久久久| 日韩亚洲欧美中文高清在线| 国产小视频91| 亲爱的老师9免费观看全集电视剧| 亚洲男人av电影| 精品亚洲一区二区三区在线观看| 国产精品中文在线| 亚洲欧美国产一本综合首页| 亚洲精品电影网| 欧美丰满片xxx777| 在线亚洲欧美视频|