Skip to content

poparray

Returns a value from an array, and a copy of the array with the value removed.

Syntax

i/koutArr[], i/kval poparray i/kinArr[], i/kndx
i/koutArr[], i/kval poparray i/kinArr[], i/kndx

Usage

poparray simultaneously retrieves a value at an index, and removes the value from an array. poparray is useful to make queue's such as last-in-first-out or first-in-first-out (LIFO & FIFO).


Outputs and arguments

i/koutArr[] -- output array

i/kval -- output value from.

i/kinArr[] -- input array

i/kndx -- index from which to retrieve the item.

Example

See the example for poparray.orc

poparray
instr Sound101
  ;; Sound source

  ares fmbell p4,p5,1,1,p6,p7,-1,-1,-1,-1,-1,p3

send ares
endin

patchsig "Sound101", "outs"
;; connect sound to output.


instr Sched14

  idur = random:i(5,12)

  ichrd[] genarray 0,14,2
  ;; generate some intervals

  ich1[],inote1 poparray ichrd, random:i(0,lenarray(ichrd))
  ich2[],inote2 poparray ich1, random:i(0,lenarray(ich1))
  ich3[],inote3 poparray ich2, random:i(0,lenarray(ich2))
  ;; select three random notes from ichrd, ensuring that no duplicate notes are selected.

  chrdi fillarray_i(n("Sound101"),0,idur,0.6,0,random:i(0.1,0.466), random:i(3,7)), fillarray_i(inote1,inote2,inote3),-3
  ;; play the chord

  schedule p1, nextbeat(idur*0.7), 1
  ;; and around again
turnoff
endin

schedule "Sched14", nextbeat(1),1
;; start the show