@p-code-magazine/p-code

Implementation of P-Code

Usage no npm install needed!

<script type="module">
  import pCodeMagazinePCode from 'https://cdn.skypack.dev/@p-code-magazine/p-code';
</script>

README

P-Code

Synopsis

P-Code is a language for live coding that evolved from the idea of describing rhythm machine patterns in text form and incorporated elements of programming. The code is interpreted from left to right, divided into numbers and other symbols, and executed. All numbers are processed as frequencies, and all symbols that cannot be interpreted are treated as white noise.

Language specification

Install & Usage

Via NPM:

npm i @p-code-magazine/p-code
import { PCode } from '@p-code-magazine/p-code';

const pcode = new PCode();
// No options supplied, "loopContext = 'external'" is default.
// You need to handle run-execute process by self.
//
// (e.g. into setInterval or requestAnimationFrame callback)
...

if (pcode.isPlaying) {
    if (pcode.hasNext()) {
        let node = pcode.tokens[pcode.pointer];
        pcode.execute(node);
        pcode.next();
    } else {
        pcode.isPlaying = false;
    }
} else {
    if (pcode.doLoop) {
        pcode.reset();
        pcode.isPlaying = true;
    } else {
        pcode.stop();
    }
}
...

or

import { PCode } from '@p-code-magazine/p-code';

const pcode = new PCode({
    // If loopContext = 'internal', p-code run as internal-loop (standalone) mode.
    loopContext: 'internal'
    // Other options, defaults are as follows:
    /*
    enableCommentSyntax: false,
    lineComment: '#',
    blockComment: /""".*?"""/g
    */
});

Via CDN (unpkg):

<script src="https://unpkg.com/@p-code-magazine/p-code" defer></script>

<script defer>
    const _pcode = new pcode.PCode();
    ...
</script>

A shrot tutorial is here, or run on CodePen

Development

Build bundle

npm i
npm run build

Run example application

Create a Self-Signed SSL Certificate. How to get https working on your local development environment in 5 minuts.

npm run example:serve

Access https://[LOCAL-SERVER-IP-ADDRESS]:8080/ on your mobile.

Build example application

npm run example:build