1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Initial Arduino IDE based on Processing.

This commit is contained in:
David A. Mellis
2005-08-25 21:06:28 +00:00
commit 9fc5aa63f6
373 changed files with 71081 additions and 0 deletions

View File

@ -0,0 +1,11 @@
/OSC-client.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
/OSC-client.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
/OSC-timetag.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
/OSC-timetag.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
/debug.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
/debug.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
/midi.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
/midi.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
/osc.c/1.1.1.1/Wed Apr 27 14:06:09 2005//
/osc.h/1.1.1.1/Wed Apr 27 14:06:09 2005//
D

View File

@ -0,0 +1 @@
Arduino/wiringlite/avrlib/ccrma

View File

@ -0,0 +1 @@
:ext:mbanzi@cvs.arduino.berlios.de:/cvsroot/arduino

View File

@ -0,0 +1,425 @@
/*
Copyright (c) 1996. The Regents of the University of California (Regents).
All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for educational, research, and not-for-profit purposes, without
fee and without a signed licensing agreement, is hereby granted, provided that
the above copyright notice, this paragraph and the following two paragraphs
appear in all copies, modifications, and distributions. Contact The Office of
Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley,
CA 94720-1620, (510) 643-7201, for commercial licensing opportunities.
Written by Matt Wright, The Center for New Music and Audio Technologies,
University of California, Berkeley.
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING
DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
*/
/*
Author: Matt Wright
Version 2.2: Calls htonl in the right places 20000620
Version 2.3: Gets typed messages right.
*/
/* Here are the possible values of the state field: */
#define EMPTY 0 /* Nothing written to packet yet */
#define ONE_MSG_ARGS 1 /* Packet has a single message; gathering arguments */
#define NEED_COUNT 2 /* Just opened a bundle; must write message name or
open another bundle */
#define GET_ARGS 3 /* Getting arguments to a message. If we see a message
name or a bundle open/close then the current message
will end. */
#define DONE 4 /* All open bundles have been closed, so can't write
anything else */
#include "OSC-client.h"
// defines to make this work with the atmel
//
#include "progmem.h"
#include "debug.h"
//#define printf debug
//
char *OSC_errorMessage;
static int OSC_padString(char *dest, char PROGMEM *str);
static int OSC_WritePadding(char *dest, int i);
static int CheckTypeTag(OSCbuf *buf, char expectedType);
void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray) {
buf->buffer = byteArray;
buf->size = size;
OSC_resetBuffer(buf);
}
void OSC_resetBuffer(OSCbuf *buf) {
buf->bufptr = buf->buffer;
buf->state = EMPTY;
buf->bundleDepth = 0;
buf->prevCounts[0] = 0;
buf->gettingFirstUntypedArg = 0;
buf->typeStringPtr = 0;
}
int OSC_isBufferEmpty(OSCbuf *buf) {
return buf->bufptr == buf->buffer;
}
int OSC_freeSpaceInBuffer(OSCbuf *buf) {
return buf->size - (buf->bufptr - buf->buffer);
}
int OSC_isBufferDone(OSCbuf *buf) {
return (buf->state == DONE || buf->state == ONE_MSG_ARGS);
}
char *OSC_getPacket(OSCbuf *buf) {
#ifdef ERROR_CHECK_GETPACKET
if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
return buf->buffer;
} else {
OSC_errorMessage = "Packet has unterminated bundles";
return 0;
}
#else
return buf->buffer;
#endif
}
int OSC_packetSize(OSCbuf *buf) {
#ifdef ERROR_CHECK_PACKETSIZE
if (buf->state == DONE || buf->state == ONE_MSG_ARGS) {
return (buf->bufptr - buf->buffer);
} else {
OSC_errorMessage = "Packet has unterminated bundles";
return 0;
}
#else
return (buf->bufptr - buf->buffer);
#endif
}
#define CheckOverflow(buf, bytesNeeded) { \
if ((bytesNeeded) > OSC_freeSpaceInBuffer(buf)) { \
OSC_errorMessage = "buffer overflow"; \
return 1; \
} \
}
static void PatchMessageSize(OSCbuf *buf) {
int4byte size;
size = buf->bufptr - ((char *) buf->thisMsgSize) - 4;
*(buf->thisMsgSize) = htonl(size);
}
int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt) {
if (buf->state == ONE_MSG_ARGS) {
OSC_errorMessage = "Can't open a bundle in a one-message packet";
return 3;
}
if (buf->state == DONE) {
OSC_errorMessage = "This packet is finished; can't open a new bundle";
return 4;
}
if (++(buf->bundleDepth) >= MAX_BUNDLE_NESTING) {
OSC_errorMessage = "Bundles nested too deeply; change MAX_BUNDLE_NESTING in OpenSoundControl.h";
return 2;
}
if (CheckTypeTag(buf, '\0')) return 9;
if (buf->state == GET_ARGS) {
PatchMessageSize(buf);
}
if (buf->state == EMPTY) {
/* Need 16 bytes for "#bundle" and time tag */
CheckOverflow(buf, 16);
} else {
/* This bundle is inside another bundle, so we need to leave
a blank size count for the size of this current bundle. */
CheckOverflow(buf, 20);
*((int4byte *)buf->bufptr) = 0xaaaaaaaa;
buf->prevCounts[buf->bundleDepth] = (int4byte *)buf->bufptr;
buf->bufptr += 4;
}
buf->bufptr += OSC_padString(buf->bufptr, "#bundle");
*((OSCTimeTag *) buf->bufptr) = tt;
if (htonl(1L) != 1L) {
/* Byte swap the 8-byte integer time tag */
int4byte *intp = (int4byte *)buf->bufptr;
intp[0] = htonl(intp[0]);
intp[1] = htonl(intp[1]);
#ifdef HAS8BYTEINT
{ /* tt is a 64-bit int so we have to swap the two 32-bit words.
(Otherwise tt is a struct of two 32-bit words, and even though
each word was wrong-endian, they were in the right order
in the struct.) */
int4byte temp = intp[0];
intp[0] = intp[1];
intp[1] = temp;
}
#endif
}
buf->bufptr += sizeof(OSCTimeTag);
buf->state = NEED_COUNT;
buf->gettingFirstUntypedArg = 0;
buf->typeStringPtr = 0;
return 0;
}
int OSC_closeBundle(OSCbuf *buf) {
if (buf->bundleDepth == 0) {
/* This handles EMPTY, ONE_MSG, ARGS, and DONE */
OSC_errorMessage = "Can't close bundle; no bundle is open!";
return 5;
}
if (CheckTypeTag(buf, '\0')) return 9;
if (buf->state == GET_ARGS) {
PatchMessageSize(buf);
}
if (buf->bundleDepth == 1) {
/* Closing the last bundle: No bundle size to patch */
buf->state = DONE;
} else {
/* Closing a sub-bundle: patch bundle size */
int4byte size = buf->bufptr - ((char *) buf->prevCounts[buf->bundleDepth]) - 4;
*(buf->prevCounts[buf->bundleDepth]) = htonl(size);
buf->state = NEED_COUNT;
}
--buf->bundleDepth;
buf->gettingFirstUntypedArg = 0;
buf->typeStringPtr = 0;
return 0;
}
int OSC_closeAllBundles(OSCbuf *buf) {
if (buf->bundleDepth == 0) {
/* This handles EMPTY, ONE_MSG, ARGS, and DONE */
OSC_errorMessage = "Can't close all bundles; no bundle is open!";
return 6;
}
if (CheckTypeTag(buf, '\0')) return 9;
while (buf->bundleDepth > 0) {
OSC_closeBundle(buf);
}
buf->typeStringPtr = 0;
return 0;
}
int OSC_writeAddress(OSCbuf *buf, char PROGMEM *name) {
int4byte paddedLength;
if (buf->state == ONE_MSG_ARGS) {
//debug(PSTR("This packet is not a bundle, so you can't write another address"));
return 7;
}
if (buf->state == DONE) {
//debug(PSTR("This packet is finished; can't write another address"));
return 8;
}
if (CheckTypeTag(buf, '\0')) return 9;
paddedLength = OSC_effectiveStringLength(name);
if (buf->state == EMPTY) {
/* This will be a one-message packet, so no sizes to worry about */
CheckOverflow(buf, paddedLength);
buf->state = ONE_MSG_ARGS;
} else {
/* GET_ARGS or NEED_COUNT */
CheckOverflow(buf, 4+paddedLength);
if (buf->state == GET_ARGS) {
/* Close the old message */
PatchMessageSize(buf);
}
buf->thisMsgSize = (int4byte *)buf->bufptr;
*(buf->thisMsgSize) = 0xbbbbbbbb;
buf->bufptr += 4;
buf->state = GET_ARGS;
}
/* Now write the name */
buf->bufptr += OSC_padString(buf->bufptr, name);
buf->typeStringPtr = 0;
buf->gettingFirstUntypedArg = 1;
return 0;
}
int OSC_writeAddressAndTypes(OSCbuf *buf, char PROGMEM *name, char PROGMEM *types) {
int result;
int4byte paddedLength;
if (CheckTypeTag(buf, '\0')) return 9;
result = OSC_writeAddress(buf, name);
if (result) return result;
paddedLength = OSC_effectiveStringLength(types);
CheckOverflow(buf, paddedLength);
buf->typeStringPtr = buf->bufptr + 1; /* skip comma */
buf->bufptr += OSC_padString(buf->bufptr, types);
buf->gettingFirstUntypedArg = 0;
return 0;
}
static int CheckTypeTag(OSCbuf *buf, char expectedType) {
if (buf->typeStringPtr) {
if (*(buf->typeStringPtr) != expectedType) {
if (expectedType == '\0') {
OSC_errorMessage =
"According to the type tag I expected more arguments.";
} else if (*(buf->typeStringPtr) == '\0') {
OSC_errorMessage =
"According to the type tag I didn't expect any more arguments.";
} else {
OSC_errorMessage =
"According to the type tag I expected an argument of a different type.";
// printf("* Expected %c, string now %s\n", expectedType, buf->typeStringPtr);
}
return 9;
}
++(buf->typeStringPtr);
}
return 0;
}
int OSC_writeFloatArg(OSCbuf *buf, float arg) {
int4byte *intp;
CheckOverflow(buf, 4);
if (CheckTypeTag(buf, 'f')) return 9;
/* Pretend arg is a long int so we can use htonl() */
intp = ((int4byte *) &arg);
*((int4byte *) buf->bufptr) = htonl(*intp);
buf->bufptr += 4;
buf->gettingFirstUntypedArg = 0;
return 0;
}
int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args) {
int i;
int4byte *intp;
CheckOverflow(buf, 4 * numFloats);
/* Pretend args are long ints so we can use htonl() */
intp = ((int4byte *) args);
for (i = 0; i < numFloats; i++) {
if (CheckTypeTag(buf, 'f')) return 9;
*((int4byte *) buf->bufptr) = htonl(intp[i]);
buf->bufptr += 4;
}
buf->gettingFirstUntypedArg = 0;
return 0;
}
int OSC_writeIntArg(OSCbuf *buf, int4byte arg) {
CheckOverflow(buf, 4);
if (CheckTypeTag(buf, 'i')) return 9;
*((int4byte *) buf->bufptr) = htonl(arg);
buf->bufptr += 4;
buf->gettingFirstUntypedArg = 0;
return 0;
}
int OSC_writeStringArg(OSCbuf *buf, char PROGMEM *arg) {
int len;
if (CheckTypeTag(buf, 's')) return 9;
len = OSC_effectiveStringLength(arg);
CheckOverflow(buf, len);
buf->bufptr += OSC_padString(buf->bufptr, arg);
buf->gettingFirstUntypedArg = 0;
return 0;
}
#define STRING_ALIGN_PAD 4
int OSC_effectiveStringLength(char PROGMEM *string) {
int len = strlen_P(string) + 1; /* We need space for the null char. */
/* Round up len to next multiple of STRING_ALIGN_PAD to account for alignment padding */
if ((len % STRING_ALIGN_PAD) != 0) {
len += STRING_ALIGN_PAD - (len % STRING_ALIGN_PAD);
}
return len;
}
static int OSC_padString(char *dest, char PROGMEM *str) {
int i;
char c;
for (i = 0; (c = pgm_read_byte(str+i)) != '\0'; i++) {
dest[i] = c;
}
return OSC_WritePadding(dest, i);
}
static int OSC_WritePadding(char *dest, int i) {
dest[i] = '\0';
i++;
for (; (i % STRING_ALIGN_PAD) != 0; i++) {
dest[i] = '\0';
}
return i;
}

View File

@ -0,0 +1,192 @@
/*
Copyright (c) 1996,1997. The Regents of the University of California (Regents).
All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for educational, research, and not-for-profit purposes, without
fee and without a signed licensing agreement, is hereby granted, provided that
the above copyright notice, this paragraph and the following two paragraphs
appear in all copies, modifications, and distributions. Contact The Office of
Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley,
CA 94720-1620, (510) 643-7201, for commercial licensing opportunities.
Written by Matt Wright, The Center for New Music and Audio Technologies,
University of California, Berkeley.
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING
DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
*/
/*
OSC-client.h: library for constructing OpenSoundControl messages.
Derived from SynthControl.h
Author: Matt Wright
Version 0.1: 6/13/97
Version 0.2: 7/21/2000: Support for type-tagged messages
General notes:
This library abstracts away the data format for the OpenSoundControl
protocol. Users of this library can construct OpenSoundControl packets
with a function call interface instead of knowing how to lay out the bits.
All issues of memory allocation are deferred to the user of this library.
There are two data structures that the user must allocate. The first
is the actual buffer that the message will be written into. This buffer
can be any size, but if it's too small there's a possibility that it
will become overfull. The other data structure is called an OSCbuf,
and it holds all the state used by the library as it's constructing
a buffer.
All procedures that have the possibility of an error condition return int,
with 0 indicating no error and nonzero indicating an error. The variable
OSC_errorMessage will be set to point to a string containing an error
message explaining what the problem is.
*/
#include "OSC-timetag.h"
#include "global.h"
#include <progmem.h>
#define ATMEL
#ifdef ATMEL
#define htonl(x) \
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#endif
/* The int4byte type has to be a 4-byte integer. You may have to
change this to long or something else on your system. */
#ifdef __MWERKS__
/* In Metrowerks you can set ints to be 2 or 4 bytes on 68K, but long is
always 4 bytes */
typedef long int4byte;
#else
typedef s32 int4byte;
#endif
/* The maximum depth of bundles within bundles within bundles within...
This is the size of a static array. If you exceed this limit you'll
get an error message. */
#define MAX_BUNDLE_NESTING 32
/* Don't ever manipulate the data in the OSCbuf struct directly. (It's
declared here in the header file only so your program will be able to
declare variables of type OSCbuf and have the right amount of memory
be allocated.) */
typedef struct OSCbuf_struct {
char *buffer; /* The buffer to hold the OSC packet */
int size; /* Size of the buffer */
char *bufptr; /* Current position as we fill the buffer */
int state; /* State of partially-constructed message */
int4byte *thisMsgSize; /* Pointer to count field before
currently-being-written message */
int4byte *prevCounts[MAX_BUNDLE_NESTING];
/* Pointers to count field before each currently
open bundle */
int bundleDepth; /* How many sub-sub-bundles are we in now? */
char *typeStringPtr; /* This pointer advances through the type
tag string as you add arguments. */
int gettingFirstUntypedArg; /* nonzero if this message doesn't have
a type tag and we're waiting for the 1st arg */
} OSCbuf;
/* Initialize the given OSCbuf. The user of this module must pass in the
block of memory that this OSCbuf will use for a buffer, and the number of
bytes in that block. (It's the user's job to allocate the memory because
you do it differently in different systems.) */
void OSC_initBuffer(OSCbuf *buf, int size, char *byteArray);
/* Reset the given OSCbuf. Do this after you send out the contents of
the buffer and want to start writing new data into it. */
void OSC_resetBuffer(OSCbuf *buf);
/* Is the buffer empty? (I.e., would it be stupid to send the buffer
contents to the synth?) */
int OSC_isBufferEmpty(OSCbuf *buf);
/* How much space is left in the buffer? */
int OSC_freeSpaceInBuffer(OSCbuf *buf);
/* Does the buffer contain a valid OSC packet? (Returns nonzero if yes.) */
int OSC_isBufferDone(OSCbuf *buf);
/* When you're ready to send out the buffer (i.e., when OSC_isBufferDone()
returns true), call these two procedures to get the OSC packet that's been
assembled and its size in bytes. (And then call OSC_resetBuffer() if you
want to re-use this OSCbuf for the next packet.) */
char *OSC_getPacket(OSCbuf *buf);
int OSC_packetSize(OSCbuf *buf);
/* Here's the basic model for building up OSC messages in an OSCbuf:
- Make sure the OSCbuf has been initialized with OSC_initBuffer().
- To open a bundle, call OSC_openBundle(). You can then write
messages or open new bundles within the bundle you opened.
Call OSC_closeBundle() to close the bundle. Note that a packet
does not have to have a bundle; it can instead consist of just a
single message.
- For each message you want to send:
- Call OSC_writeAddress() with the name of your message. (In
addition to writing your message name into the buffer, this
procedure will also leave space for the size count of this message.)
- Alternately, call OSC_writeAddressAndTypes() with the name of
your message and with a type string listing the types of all the
arguments you will be putting in this message.
- Now write each of the arguments into the buffer, by calling one of:
OSC_writeFloatArg()
OSC_writeFloatArgs()
OSC_writeIntArg()
OSC_writeStringArg()
- Now your message is complete; you can send out the buffer or you can
add another message to it.
*/
int OSC_openBundle(OSCbuf *buf, OSCTimeTag tt);
int OSC_closeBundle(OSCbuf *buf);
int OSC_closeAllBundles(OSCbuf *buf);
int OSC_writeAddress(OSCbuf *buf, char PROGMEM *name);
int OSC_writeAddressAndTypes(OSCbuf *buf, char PROGMEM *name, char PROGMEM *types);
int OSC_writeFloatArg(OSCbuf *buf, float arg);
int OSC_writeFloatArgs(OSCbuf *buf, int numFloats, float *args);
int OSC_writeIntArg(OSCbuf *buf, int4byte arg);
int OSC_writeStringArg(OSCbuf *buf, char PROGMEM *arg);
extern char *OSC_errorMessage;
/* How many bytes will be needed in the OSC format to hold the given
string? The length of the string, plus the null char, plus any padding
needed for 4-byte alignment. */
int OSC_effectiveStringLength(char PROGMEM *string);

View File

@ -0,0 +1,175 @@
/*
Copyright (c) 1998. The Regents of the University of California (Regents).
All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for educational, research, and not-for-profit purposes, without
fee and without a signed licensing agreement, is hereby granted, provided that
the above copyright notice, this paragraph and the following two paragraphs
appear in all copies, modifications, and distributions. Contact The Office of
Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley,
CA 94720-1620, (510) 643-7201, for commercial licensing opportunities.
Written by Matt Wright, The Center for New Music and Audio Technologies,
University of California, Berkeley.
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING
DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
The OpenSound Control WWW page is
http://www.cnmat.berkeley.edu/OpenSoundControl
*/
/*
OSC_timeTag.c: library for manipulating OSC time tags
Matt Wright, 5/29/97
Version 0.2 (9/11/98): cleaned up so no explicit type names in the .c file.
*/
#include "OSC-timetag.h"
#ifdef HAS8BYTEINT
#define TWO_TO_THE_32_FLOAT 4294967296.0f
OSCTimeTag OSCTT_Immediately(void) {
return (OSCTimeTag) 1;
}
OSCTimeTag OSCTT_BiggestPossibleTimeTag(void) {
return (OSCTimeTag) 0xffffffffffffffff;
}
OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) {
int64 offset = (int64) (secondsOffset * TWO_TO_THE_32_FLOAT);
/* printf("* OSCTT_PlusSeconds %llx plus %f seconds (i.e., %lld offset) is %llx\n", original,
secondsOffset, offset, original + offset); */
return original + offset;
}
int OSCTT_Compare(OSCTimeTag left, OSCTimeTag right) {
#if 0
printf("***** OSCTT_Compare(%llx, %llx): %d\n", left, right,
(left<right) ? -1 : ((left == right) ? 0 : 1));
#endif
if (left < right) {
return -1;
} else if (left == right) {
return 0;
} else {
return 1;
}
}
#ifdef __sgi
#include <sys/time.h>
#define SECONDS_FROM_1900_to_1970 2208988800 /* 17 leap years */
#define TWO_TO_THE_32_OVER_ONE_MILLION 4295
OSCTimeTag OSCTT_CurrentTime(void) {
uint64 result;
uint32 usecOffset;
struct timeval tv;
struct timezone tz;
BSDgettimeofday(&tv, &tz);
/* First get the seconds right */
result = (unsigned) SECONDS_FROM_1900_to_1970 +
(unsigned) tv.tv_sec -
(unsigned) 60 * tz.tz_minuteswest +
(unsigned) (tz.tz_dsttime ? 3600 : 0);
#if 0
/* No timezone, no DST version ... */
result = (unsigned) SECONDS_FROM_1900_to_1970 +
(unsigned) tv.tv_sec;
#endif
/* make seconds the high-order 32 bits */
result = result << 32;
/* Now get the fractional part. */
usecOffset = (unsigned) tv.tv_usec * (unsigned) TWO_TO_THE_32_OVER_ONE_MILLION;
/* printf("** %ld microsec is offset %x\n", tv.tv_usec, usecOffset); */
result += usecOffset;
/* printf("* OSCTT_CurrentTime is %llx\n", result); */
return result;
}
#else /* __sgi */
/* Instead of asking your operating system what time it is, it might be
clever to find out the current time at the instant your application
starts audio processing, and then keep track of the number of samples
output to know how much time has passed. */
/* Loser version for systems that have no ability to tell the current time: */
OSCTimeTag OSCTT_CurrentTime(void) {
return (OSCTimeTag) 1;
}
#endif /* __sgi */
#else /* Not HAS8BYTEINT */
OSCTimeTag OSCTT_CurrentTime(void) {
OSCTimeTag result;
result.seconds = 0;
result.fraction = 1;
return result;
}
OSCTimeTag OSCTT_BiggestPossibleTimeTag(void) {
OSCTimeTag result;
result.seconds = 0xffffffff;
result.fraction = 0xffffffff;
return result;
}
OSCTimeTag OSCTT_Immediately(void) {
OSCTimeTag result;
result.seconds = 0;
result.fraction = 1;
return result;
}
OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset) {
OSCTimeTag result;
result.seconds = 0;
result.fraction = 1;
return result;
}
int OSCTT_Compare(OSCTimeTag left, OSCTimeTag right) {
/* Untested! */
int highResult = left.seconds - right.seconds;
if (highResult != 0) return highResult;
return left.fraction - right.fraction;
}
#endif /* HAS8BYTEINT */

View File

@ -0,0 +1,95 @@
/*
Copyright (c) 1998. The Regents of the University of California (Regents).
All Rights Reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for educational, research, and not-for-profit purposes, without
fee and without a signed licensing agreement, is hereby granted, provided that
the above copyright notice, this paragraph and the following two paragraphs
appear in all copies, modifications, and distributions. Contact The Office of
Technology Licensing, UC Berkeley, 2150 Shattuck Avenue, Suite 510, Berkeley,
CA 94720-1620, (510) 643-7201, for commercial licensing opportunities.
Written by Matt Wright, The Center for New Music and Audio Technologies,
University of California, Berkeley.
IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING
DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
ENHANCEMENTS, OR MODIFICATIONS.
The OpenSound Control WWW page is
http://www.cnmat.berkeley.edu/OpenSoundControl
*/
/*
OSC_timeTag.h: library for manipulating OSC time tags
Matt Wright, 5/29/97
Time tags in OSC have the same format as in NTP: 64 bit fixed point, with the
top 32 bits giving number of seconds sinve midnight 1/1/1900 and the bottom
32 bits giving fractional parts of a second. We represent this by a 64-bit
unsigned long if possible, or else a struct.
NB: On many architectures with 64-bit ints, it's illegal (like maybe a bus error)
to dereference a pointer to a 64-bit int that's not 64-bit aligned.
*/
#ifndef OSC_TIMETAG
#define OSC_TIMETAG
#include <inttypes.h>
#ifdef __sgi
#define HAS8BYTEINT
/* You may have to change this typedef if there's some other
way to specify 64 bit ints on your system */
typedef long long int64;
typedef unsigned long long uint64;
typedef unsigned long uint32;
#else
/* You may have to redefine this typedef if ints on your system
aren't 32 bits. */
typedef uint32_t uint32;
#endif
#ifdef HAS8BYTEINT
typedef uint64 OSCTimeTag;
#else
typedef struct {
uint32 seconds;
uint32 fraction;
} OSCTimeTag;
#endif
/* Return a time tag representing the current time (as of when this
procedure is called). */
OSCTimeTag OSCTT_CurrentTime(void);
/* Return the time tag 0x0000000000000001, indicating to the receiving device
that it should process the message immediately. */
OSCTimeTag OSCTT_Immediately(void);
/* Return the time tag 0xffffffffffffffff, a time so far in the future that
it's effectively infinity. */
OSCTimeTag OSCTT_BiggestPossibleTimeTag(void);
/* Given a time tag and a number of seconds to add to the time tag, return
the new time tag */
OSCTimeTag OSCTT_PlusSeconds(OSCTimeTag original, float secondsOffset);
/* Compare two time tags. Return negative if first is < second, 0 if
they're equal, and positive if first > second. */
int OSCTT_Compare(OSCTimeTag left, OSCTimeTag right);
#endif /* OSC_TIMETAG */

View File

@ -0,0 +1,55 @@
#include <io.h>
#include <stdarg.h>
#include "debug.h"
#include "lcd.h"
#include "rprintf.h"
#include "timer.h"
#include "osc.h"
u08 debugMode = 0;
u08 lcdDebugX;
u08 lcdDebugY;
void debugInitLCD(u08 x, u08 y) {
lcdInit();
lcdClear();
lcdDebugX = x;
lcdDebugY = y;
debugMode |= DEBUG_MODE_LCD;
debug(PSTR("LCD Debug init()"));
}
void debugInitOSC(void) {
oscInit();
debugMode |= DEBUG_MODE_OSC;
}
void debug(const char PROGMEM *fmt) {
int code;
if (debugMode & DEBUG_MODE_OSC) {
oscSendMessageString("/debug",fmt);
}
if (debugMode & DEBUG_MODE_LCD) {
rprintfInit(&lcdDataWrite);
lcdGotoXY(lcdDebugX,lcdDebugY);
rprintf1RamRom(STRING_IN_ROM, fmt);
}
}
// debugFlush assumes that timerInit() have been called already
void debugFlash(const u08 port, const u08 pin) {
sbi(DDR(port), pin);
cbi(port, pin);
timerPause(500);
sbi(port, pin);
}

View File

@ -0,0 +1,22 @@
#ifndef _DEBUG_H
#define _DEBUG_H
#include <progmem.h>
#include "global.h"
#define DEBUG_MODE_LCD 0x01
#define DEBUG_MODE_SERIAL 0x02
#define DEBUG_MODE_OSC 0x04
void debugInitLCD(u08 x, u08 y);
void debugInitOSC(void);
void debug(const char * fmt);
void debugFlash(u08 port, u08 pin);
#endif

View File

@ -0,0 +1,48 @@
// Midi.c
//
// Midi output routines for the atmel atmega163 (and others)
//
// depends on avrlib for buffer
//
#include "uart.h"
#include "midi.h"
#include "debug.h"
void midiInit() {
uartInit();
uartSetBaudRate(MIDI_BAUD_RATE);
}
u08 midiNoteOnOut(u08 note, u08 vel, u08 channel) {
uartSendByte(MIDI_NOTE_ON | (channel & MIDI_CHANNEL_MASK));
uartSendByte(MIDI_DATA_MASK & note);
uartSendByte(MIDI_DATA_MASK & vel);
return 0;
}
u08 midiNoteOffOut(u08 note, u08 vel, u08 channel) {
uartSendByte(MIDI_NOTE_OFF | (channel & MIDI_CHANNEL_MASK));
uartSendByte(MIDI_DATA_MASK & note);
uartSendByte(MIDI_DATA_MASK & vel);
return 0;
}
u08 midiControlChangeOut(u08 controller, u08 value, u08 channel) {
uartSendByte(MIDI_CONTROL_CHANGE | (channel & MIDI_CHANNEL_MASK));
uartSendByte(MIDI_DATA_MASK & controller);
uartSendByte(MIDI_DATA_MASK & value);
return 0;
}
u08 midiProgramChangeOut(u08 program, u08 channel) {
uartSendByte(MIDI_PROGRAM_CHANGE | (channel & MIDI_CHANNEL_MASK));
uartSendByte(MIDI_DATA_MASK & program);
return 0;
}

View File

@ -0,0 +1,30 @@
#ifndef _MIDI_H
#define _MIDI_H
#define MIDI_NOTE_ON 0x90
#define MIDI_NOTE_OFF 0x80
// 1001cccc 0nnnnnnn 0vvvvvvv
#define MIDI_POLY_PRESSURE 0xA0
// 1011cccc 0nnnnnnn 0vvvvvvv
#define MIDI_CONTROL_CHANGE 0xB0
// 1100cccc 0ppppppp
#define MIDI_PROGRAM_CHANGE 0xC0
#define MIDI_DATA_MASK 0x7F
#define MIDI_STATUS_MASK 0xF0
#define MIDI_CHANNEL_MASK 0x0F
#define MIDI_BAUD_RATE 31250
#include "global.h"
#include "buffer.h"
void midiInit(void);
u08 midiNoteOnOut(u08 note, u08 vel, u08 channel);
u08 midiNoteOffOut(u08 note, u08 vel, u08 channel);
u08 midiControlChangeOut(u08 controller, u08 value, u08 channel);
u08 midiProgramChangeOut(u08 program, u08 channel);
#endif

View File

@ -0,0 +1,96 @@
// osc.c
//
// Open Sound Control message sending fn's for avrmini
//
// Scott Wilson
// July 21, 2002
//
#include <progmem.h>
#include <stdarg.h>
#include "OSC-client.h"
#include "osc.h"
//#include "debug.h"
#include "uart.h"
#define OSC_BUFFER_LEN 40
void _oscSendPacket();
u08 oscDataBuffer[OSC_BUFFER_LEN];
OSCbuf oscbuf;
void oscInit() {
uartInit();
OSC_initBuffer(&oscbuf, OSC_BUFFER_LEN, oscDataBuffer);
// debug(PSTR("OSC init ok packet"));
}
// call oscInit() and uartInit() before using this function
void oscSendMessage(const char PROGMEM *address) {
OSC_writeAddress(&oscbuf, address);
_oscSendPacket();
}
void oscSendMessageInt(const char PROGMEM *address, s32 arg) {
OSC_writeAddress(&oscbuf, address);
OSC_writeIntArg(&oscbuf, arg);
_oscSendPacket();
}
void oscSendMessageIntInt(const char PROGMEM *address, s32 arg, s32 arg2) {
OSC_writeAddress(&oscbuf, address);
OSC_writeIntArg(&oscbuf, arg);
OSC_writeIntArg(&oscbuf, arg2);
_oscSendPacket();
}
void oscSendMessageString(const char PROGMEM *address, const char PROGMEM *arg) {
OSC_writeAddress(&oscbuf, address);
OSC_writeStringArg(&oscbuf, arg);
_oscSendPacket();
}
void _oscSendPacket() {
u08 j;
u08 *oscDataPtr;
u08 oscPacketSize;
register u08 checksum=0;
register u08 data;
// send the packet
if (OSC_isBufferDone(&oscbuf)) {
// begin packet sync byte
uartSendByte((u08)0xbe);
// send length byte
uartSendByte((u08)(OSC_BUFFER_LEN - OSC_freeSpaceInBuffer(&oscbuf)));
oscDataPtr = OSC_getPacket(&oscbuf);
oscPacketSize = OSC_packetSize(&oscbuf);
// debug(PSTR("packet size: %x"),(unsigned int)oscPacketSize);
for (j=0; j<oscPacketSize; j++) {
data = *(oscDataPtr+j);
checksum += data;
uartSendByte(data);
}
// send checksum byte
uartSendByte(checksum);
OSC_resetBuffer(&oscbuf);
} else {
//debug(PSTR("Error creating OSC packet"));
}
}

View File

@ -0,0 +1,24 @@
// osc.h
//
// Open Sound Control message sending fn's for avrmini
//
// Scott Wilson
// July 21, 2002
//
#ifndef _OSC_H
#define _OSC_H
#include "global.h"
#include <progmem.h>
#define oscSendMessageOneArg oscSendMessageInt
void oscInit(void);
void oscSendMessage(const char PROGMEM *address);
void oscSendMessageInt(const char PROGMEM *address, s32 arg);
void oscSendMessageIntInt(const char PROGMEM *address, s32 arg, s32 arg2);
void oscSendMessageString(const char PROGMEM *address, const char PROGMEM *arg);
#endif