Permalink
Browse files

Fix logic flaw in [toggle]. Tests updated.

  • Loading branch information...
1 parent 5f4cdc2 commit b8fb31b365bdaf49cf5bd8def058ed8b6419aeae @mhroth committed Sep 15, 2011
Showing with 24 additions and 24 deletions.
  1. +6 −8 src/MessageToggle.cpp
  2. +2 −2 src/MessageToggle.h
  3. +1 −0 test/MessageToggle.golden
  4. +15 −14 test/MessageToggle.pd
View
@@ -28,7 +28,7 @@ MessageObject *MessageToggle::newObject(PdMessage *initMessage, PdGraph *graph)
MessageToggle::MessageToggle(PdMessage *initString, PdGraph *graph) : MessageObject(1, 1, graph) {
isOn = false;
- lastOutput = 0.0f;
+ onOutput = 1.0f;
}
MessageToggle::~MessageToggle() {
@@ -43,30 +43,28 @@ void MessageToggle::processMessage(int inletIndex, PdMessage *message) {
switch (message->getType(0)) {
case FLOAT: {
isOn = (message->getFloat(0) != 0.0f);
- if (isOn) lastOutput = message->getFloat(0);
+ if (isOn) onOutput = message->getFloat(0);
PdMessage *outgoingMessage = PD_MESSAGE_ON_STACK(1);
- outgoingMessage->initWithTimestampAndFloat(message->getTimestamp(), isOn ? message->getFloat(0) : 0.0f);
+ outgoingMessage->initWithTimestampAndFloat(message->getTimestamp(), isOn ? onOutput : 0.0f);
sendMessage(0, outgoingMessage);
break;
}
case BANG: {
isOn = !isOn;
PdMessage *outgoingMessage = PD_MESSAGE_ON_STACK(1);
- outgoingMessage->initWithTimestampAndFloat(message->getTimestamp(), isOn ? lastOutput : 0.0f);
+ outgoingMessage->initWithTimestampAndFloat(message->getTimestamp(), isOn ? onOutput : 0.0f);
sendMessage(0, outgoingMessage);
break;
}
case SYMBOL: {
if (message->isSymbol(0, "set")) {
- lastOutput = 1.0f;
if (message->isFloat(1)) {
isOn = (message->getFloat(1) != 0.0f);
+ if (isOn) onOutput = message->getFloat(1);
}
}
break;
}
- default: {
- break;
- }
+ default: break;
}
}
View
@@ -1,5 +1,5 @@
/*
- * Copyright 2009,2010 Reality Jockey, Ltd.
+ * Copyright 2009,2010,2011 Reality Jockey, Ltd.
* info@rjdj.me
* http://rjdj.me/
*
@@ -39,7 +39,7 @@ class MessageToggle : public MessageObject {
void processMessage(int inletIndex, PdMessage *message);
bool isOn;
- float lastOutput;
+ float onOutput;
};
#endif // _MESSAGE_TOGGLE_H_
@@ -1,3 +1,4 @@
+[@ 0.000ms] print: 1
[@ 0.000ms] print: 33
[@ 0.000ms] print: 0
[@ 0.000ms] print: 0
View
@@ -1,31 +1,32 @@
-#N canvas 746 271 450 300 10;
+#N canvas 364 200 450 300 10;
#X obj 63 19 loadbang;
#X obj 133 19 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
-#X obj 98 150 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
+#X obj 98 150 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X msg 204 105 33;
#X msg 168 105 0;
#X obj 98 179 print;
#X msg 120 105 -12.9;
#X msg 75 105 set 1;
-#X obj 62 55 t b b b b b b b b b b;
#X msg 32 105 set 0;
-#X connect 0 0 8 0;
-#X connect 1 0 8 0;
+#X obj 62 55 t b b b b b b b b b b b;
+#X connect 0 0 9 0;
+#X connect 1 0 9 0;
#X connect 2 0 5 0;
#X connect 3 0 2 0;
#X connect 4 0 2 0;
#X connect 6 0 2 0;
#X connect 7 0 2 0;
#X connect 8 0 2 0;
-#X connect 8 1 9 0;
-#X connect 8 2 2 0;
-#X connect 8 3 7 0;
-#X connect 8 4 2 0;
-#X connect 8 5 6 0;
-#X connect 8 6 2 0;
-#X connect 8 7 4 0;
-#X connect 8 8 2 0;
-#X connect 8 9 3 0;
#X connect 9 0 2 0;
+#X connect 9 1 8 0;
+#X connect 9 2 2 0;
+#X connect 9 3 7 0;
+#X connect 9 4 2 0;
+#X connect 9 5 6 0;
+#X connect 9 6 2 0;
+#X connect 9 7 4 0;
+#X connect 9 8 2 0;
+#X connect 9 9 3 0;
+#X connect 9 10 2 0;

0 comments on commit b8fb31b

Please sign in to comment.