Skip to content

Commit

Permalink
added MessageDbToRms, MessageRmsToDb, MessageMaximum, MessageMinimum,…
Browse files Browse the repository at this point in the history
… MessageFrequencyToMidi and MessageMidiToFrequency
  • Loading branch information
Yoonchang Han committed Mar 12, 2010
1 parent f0a4f07 commit 0361067
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 172 deletions.
6 changes: 6 additions & 0 deletions src/Makefile.sourcefiles
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ LOCAL_SRC_FILES := \
./MessageChange.cpp \
./MessageCosine.cpp \
./MessageDbToPow.cpp \
./MessageDbToRms.cpp \
./MessageDelay.cpp \
./MessageDivide.cpp \
./MessageElement.cpp \
./MessageEqualsEquals.cpp \
./MessageExp.cpp \
./MessageFloat.cpp \
./MessageFrequencyToMidi.cpp \
./MessageGreaterThan.cpp \
./MessageGreaterThanOrEqualTo.cpp \
./MessageInlet.cpp \
Expand All @@ -32,8 +34,11 @@ LOCAL_SRC_FILES := \
./MessageLessThanOrEqualTo.cpp \
./MessageLoadbang.cpp \
./MessageLog.cpp \
./MessageMaximum.cpp \
./MessageMessageBox.cpp \
./MessageMetro.cpp \
./MessageMidiToFrequency.cpp \
./MessageMinimum.cpp \
./MessageMultiply.cpp \
./MessageNamedObject.cpp \
./MessageNotEquals.cpp \
Expand All @@ -47,6 +52,7 @@ LOCAL_SRC_FILES := \
./MessageQueue.cpp \
./MessageRandom.cpp \
./MessageReceive.cpp \
./MessageRmsToDb.cpp \
./MessageSend.cpp \
./MessageSine.cpp \
./MessageSqrt.cpp \
Expand Down
13 changes: 5 additions & 8 deletions src/MessageDbToPow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ const char *MessageDbToPow::getObjectLabel() {
}

void MessageDbToPow::processMessage(int inletIndex, PdMessage *message) {
if (inletIndex == 0) {
MessageElement *messageElement = message->getElement(0);
if (messageElement->getType() == FLOAT) {
PdMessage *outgoingMessage = getNextOutgoingMessage(0);
outgoingMessage->getElement(0)->setFloat(powf(0.00001f * powf(10.0f,(messageElement->getFloat())/20.0f),2.0f));
outgoingMessage->setTimestamp(message->getTimestamp());
sendMessage(0, outgoingMessage); // send a message from outlet 0
}
if (message->getElement(0)->getType() == FLOAT) {
PdMessage *outgoingMessage = getNextOutgoingMessage(0);
outgoingMessage->getElement(0)->setFloat(powf(0.00001f * powf(10.0f,(message->getElement(0)->getFloat())/20.0f),2.0f));
outgoingMessage->setTimestamp(message->getTimestamp());
sendMessage(0, outgoingMessage); // send a message from outlet 0
}
}
22 changes: 15 additions & 7 deletions src/MessageDbToRms.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright 2009 Reality Jockey, Ltd.
* Copyright 2009, 2010 Reality Jockey, Ltd.
* info@rjdj.me
* http://rjdj.me/
*
*
* This file is part of ZenGarden.
*
* ZenGarden is free software: you can redistribute it and/or modify
Expand All @@ -14,23 +14,31 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <math.h>
#include "MessageDbToRms.h"

MessageDbToRms::MessageDbToRms(char *initString) : MessageUnaryOperationObject(initString) {
MessageDbToRms::MessageDbToRms(PdGraph *graph) : MessageObject(1, 1, graph) {
// nothing to do
}

MessageDbToRms::~MessageDbToRms() {
// nothing to do
}

float MessageDbToRms::performUnaryOperation(float input) {
return 0.00001f * powf(10.0f, input / 20.0f);
const char *MessageDbToRms::getObjectLabel() {
return "dbtorms";
}

void MessageDbToRms::processMessage(int inletIndex, PdMessage *message) {
if (message->getElement(0)->getType() == FLOAT) {
PdMessage *outgoingMessage = getNextOutgoingMessage(0);
outgoingMessage->getElement(0)->setFloat(0.00001f * powf(10.0f, message->getElement(0)->getFloat() / 20.0f));
outgoingMessage->setTimestamp(message->getTimestamp());
sendMessage(0, outgoingMessage); // send a message from outlet 0
}
}
31 changes: 18 additions & 13 deletions src/MessageDbToRms.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright 2009 Reality Jockey, Ltd.
* Copyright 2009,2010 Reality Jockey, Ltd.
* info@rjdj.me
* http://rjdj.me/
*
*
* This file is part of ZenGarden.
*
* ZenGarden is free software: you can redistribute it and/or modify
Expand All @@ -14,25 +14,30 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef _MESSAGE_DB_TO_RMS_H_
#define _MESSAGE_DB_TO_RMS_H_
#ifndef _MESSAGE_DBTORMS_H_
#define _MESSAGE_DBTORMS_H_


#include "MessageUnaryOperationObject.h"
#include "math.h"
#include "MessageObject.h"

/** [dbtorms] */
class MessageDbToRms : public MessageObject {

class MessageDbToRms : public MessageUnaryOperationObject {

public:
MessageDbToRms(char *initString);
MessageDbToRms(PdGraph *graph);
~MessageDbToRms();

protected:
float performUnaryOperation(float input);

const char *getObjectLabel();

private:
void processMessage(int inletIndex, PdMessage *message);
};

#endif // _MESSAGE_DB_TO_RMS_H_
#endif // _MESSAGE_DBTORMS_H_
2 changes: 1 addition & 1 deletion src/MessageDivide.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ class MessageDivide : public MessageObject {
float constant;
};

#endif // _MESSAGE_ADD_H_
#endif // _MESSAGE_DIVIDE_H_
23 changes: 16 additions & 7 deletions src/MessageFrequencyToMidi.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright 2009 Reality Jockey, Ltd.
* Copyright 2009, 2010 Reality Jockey, Ltd.
* info@rjdj.me
* http://rjdj.me/
*
*
* This file is part of ZenGarden.
*
* ZenGarden is free software: you can redistribute it and/or modify
Expand All @@ -14,23 +14,32 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <math.h>
#include "MessageFrequencyToMidi.h"

MessageFrequencyToMidi::MessageFrequencyToMidi(char *initString) : MessageUnaryOperationObject(initString) {
MessageFrequencyToMidi::MessageFrequencyToMidi(PdGraph *graph) : MessageObject(1, 1, graph) {
// nothing to do
}

MessageFrequencyToMidi::~MessageFrequencyToMidi() {
// nothing to do
}

inline float MessageFrequencyToMidi::performUnaryOperation(float input) {
return (12.0f * (logf(input/440.0f) / M_LN2)) + 69.0f;
const char *MessageFrequencyToMidi::getObjectLabel() {
return "ftom";
}

void MessageFrequencyToMidi::processMessage(int inletIndex, PdMessage *message) {
if (message->getElement(0)->getType() == FLOAT) {
PdMessage *outgoingMessage = getNextOutgoingMessage(0);
int f = message->getElement(0)->getFloat();
outgoingMessage->getElement(0)->setFloat((f < 0.0f) ? -1500.0f : (12.0f * (logf(f / 440.0f) / M_LN2)) + 69.0f);
outgoingMessage->setTimestamp(message->getTimestamp());
sendMessage(0, outgoingMessage); // send a message from outlet 0
}
}
33 changes: 17 additions & 16 deletions src/MessageFrequencyToMidi.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright 2009 Reality Jockey, Ltd.
* Copyright 2009,2010 Reality Jockey, Ltd.
* info@rjdj.me
* http://rjdj.me/
*
*
* This file is part of ZenGarden.
*
* ZenGarden is free software: you can redistribute it and/or modify
Expand All @@ -14,28 +14,29 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef _MESSAGE_FREQUENCY_TO_MIDI_H_
#define _MESSAGE_FREQUENCY_TO_MIDI_H_
#ifndef _MESSAGE_FREQUENCYTOMIDI_H_
#define _MESSAGE_FREQUENCYTOMIDI_H_

#include "MessageUnaryOperationObject.h"
#include <math.h>
#include "MessageObject.h"

/** [ftom] */
class MessageFrequencyToMidi : public MessageObject {

/**
* ftom
*/
class MessageFrequencyToMidi : public MessageUnaryOperationObject {

public:
MessageFrequencyToMidi(char *initString);
MessageFrequencyToMidi(PdGraph *graph);
~MessageFrequencyToMidi();

protected:
inline float performUnaryOperation(float input);

const char *getObjectLabel();

private:
void processMessage(int inletIndex, PdMessage *message);
};

#endif // _MESSAGE_FREQUENCY_TO_MIDI_H_
#endif // _MESSAGE_FREQUENCYTOMIDI_H_
55 changes: 43 additions & 12 deletions src/MessageMaximum.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright 2009 Reality Jockey, Ltd.
* Copyright 2009, 2010 Reality Jockey, Ltd.
* info@rjdj.me
* http://rjdj.me/
*
*
* This file is part of ZenGarden.
*
* ZenGarden is free software: you can redistribute it and/or modify
Expand All @@ -14,29 +14,60 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenGarden. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include <math.h>
#include "MessageMaximum.h"

MessageMaximum::MessageMaximum(char *initString) : MessageBinaryOperationObject(initString) {
left = 0.0f;
right = 0.0f;
MessageMaximum::MessageMaximum(PdMessage *initMessage, PdGraph *graph) : MessageObject(2, 1, graph) {
if (initMessage->getNumElements() > 0 &&
initMessage->getElement(0)->getType() == FLOAT) {
init(initMessage->getElement(0)->getFloat());
} else {
init(0.0f);
}
}

MessageMaximum::MessageMaximum(float constant, char *initString) : MessageBinaryOperationObject(initString) {
left = 0.0f;
right = constant;
MessageMaximum::MessageMaximum(float constant, PdGraph *graph) : MessageObject(2, 1, graph) {
init(constant);
}

MessageMaximum::~MessageMaximum() {
// nothing to do
}

float MessageMaximum::performBinaryOperation(float left, float right) {
return fmaxf(left, right);
void MessageMaximum::init(float constant) {
this->constant = constant;
}

const char *MessageMaximum::getObjectLabel() {
return "max";
}

void MessageMaximum::processMessage(int inletIndex, PdMessage *message) {
switch (inletIndex) {
case 0: {
MessageElement *messageElement = message->getElement(0);
if (messageElement->getType() == FLOAT) {
PdMessage *outgoingMessage = getNextOutgoingMessage(0);
outgoingMessage->getElement(0)->setFloat(fmaxf(messageElement->getFloat(),constant));
outgoingMessage->setTimestamp(message->getTimestamp());
sendMessage(0, outgoingMessage); // send a message from outlet 0
}
break;
}
case 1: {
MessageElement *messageElement = message->getElement(0);
if (messageElement->getType() == FLOAT) {
constant = messageElement->getFloat();
}
break;
}
default: {
break;
}
}
}
Loading

0 comments on commit 0361067

Please sign in to comment.