reshapearray
Prev | Orchestra Opcodes and Operators | Next

## reshapearray

reshapearray — Reshape an array, maintaining its capacity

## Description

Plugin opcode in emugens.

The reshapearray opcode changes the shape of an array, as long as this does not modify its capacity. It can be used to convert a 1D to a 2D array, or viceversa, or simply to modify the size of its dimensions, as long as the product remains constant.

## Syntax

    reshapearray array[], isize0 [, isize1 ]

## Initialization

array[] - The array to be reshaped (this is done inplace)

isize0 - The size of the first dimension

isize1 - The size of the second dimension (0 for 1D arrays). Defaults to 0

## Examples

Here is an example of the reshapearray opcode. It uses the file reshapearray.csd.

Example 838. Example of the reshapearray opcode.

    <CsoundSynthesizer>
    <CsOptions>
    ;-odac     ;;;realtime audio out

    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 64
    nchnls = 2
    0dbfs  = 1

    ; This is the example file for reshapearray

    /*

    reshapearray

      Reshape an array, maintaining the capacity of the array
      (it does NOT resize the array).

      You can reshape a 2D array to another array of equal capacity
      of reshape a 1D array to a 2D array, or a 2D array to a 1D
      array

      reshapearray array[], inumrows, inumcols=0

      works with i and k arrays, at i-time and k-time

    */

    instr 1
      ivalues[] fillarray 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
      printarray ivalues
      reshapearray ivalues, 3, 4
      printarray ivalues
    endin

    instr 2
      kxs[][] init 3, 4
      kxs fillarray   0,  1,  2,  3, \
                     10, 11, 12, 13, \
                     20, 21, 22, 23
      reshapearray kxs, 4, 3
      printarray kxs, 1, "", "kxs after"
      turnoff
    endin

    </CsInstruments>

    <CsScore>
    i 1 0 0.01
    i 2 1 0.05
    </CsScore>

    </CsoundSynthesizer>

## See Also

printarray, getrow, slicearray,

## Credits

By: Eduardo Moguillansky 2018

New plugin in version 6.12

Prev | Up | Next
repluck | Home | reson