Code/Bug Trouble

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Code/Bug Trouble

Post by dudmaster »

Hello, It's Dud.

I am having trouble with my AudioEditor program. I wonder what's causing this. Can you guys help?

Code:

Code: Select all

int L, Curser, C2, Octave = 200;
int Note[100];

task main() {
SetAbortFlag(0x04);
SetSensorLowspeed(S1);
SetSensorMode(S1, SENSOR_MODE_BOOL);
SetSensorType(S1, SENSOR_TYPE_TOUCH);
SetSensorLowspeed(S2);
SetSensorMode(S2, SENSOR_MODE_BOOL);
SetSensorType(S2, SENSOR_TYPE_TOUCH);

// Initialize

while (true) {
while (0 == Sensor(S1))
{
if (Sensor(S2) == 1)
{
MenuM:
int LinkNumber = 0;
while (false == ButtonCount(BTNCENTER,true))
{
TextOut(0, LCD_LINE1, "Main Menu", true);
LineOut(0, 54, 99, 54);
if (LinkNumber == 0)
{
TextOut(0, LCD_LINE3, "Octave", DRAW_OPT_INVERT);
TextOut(0, LCD_LINE4, "Save");
TextOut(0, LCD_LINE5, "Generate");
TextOut(0, LCD_LINE6, "Back");
}
if (LinkNumber == 1)
{
TextOut(0, LCD_LINE3, "Octave");
TextOut(0, LCD_LINE4, "Save", DRAW_OPT_INVERT);
TextOut(0, LCD_LINE5, "Generate");
TextOut(0, LCD_LINE6, "Back");
}
if (LinkNumber == 2)
{
TextOut(0, LCD_LINE3, "Octave");
TextOut(0, LCD_LINE4, "Save");
TextOut(0, LCD_LINE5, "Generate", DRAW_OPT_INVERT);
TextOut(0, LCD_LINE6, "Back");
}
if (LinkNumber == 3)
{
TextOut(0, LCD_LINE3, "Octave");
TextOut(0, LCD_LINE4, "Save");
TextOut(0, LCD_LINE5, "Generate");
TextOut(0, LCD_LINE6, "Back", DRAW_OPT_INVERT);
}
if (1 == ButtonCount(BTNLEFT,true))
{
  if (0 < LinkNumber)
  {
  LinkNumber = LinkNumber - 1;
  }
}
if (1 == ButtonCount(BTNRIGHT,true))
{
  if (3 > LinkNumber)
  {
  LinkNumber = LinkNumber + 1;
  }
}
Wait(15);
}
if (LinkNumber == 0)
{
string T;
while (false == ButtonCount(BTNCENTER, true))
{
TextOut(0, LCD_LINE1, "Octave Control", true);
LineOut(0, 54, 99, 54);
T = NumToStr(Octave);
TextOut(0, LCD_LINE3, "O: " + T);
if (1 == ButtonCount(BTNLEFT,true))
{
  if (200 < Octave)
  {
  Octave = Octave - 50;
  }
}
if (1 == ButtonCount(BTNRIGHT,true))
{
  if (300 > LinkNumber)
  {
  Octave = Octave + 50;
  }
}
Wait(50);
}
}
if (LinkNumber == 1)
{
int Lnk;
while (false == ButtonCount(BTNCENTER,true))
{
TextOut(0, LCD_LINE1, "Save File", true);
LineOut(0, 54, 99, 54);
if (Lnk == 0)
{
TextOut(0, LCD_LINE3, "NXC", DRAW_OPT_INVERT);
TextOut(0, LCD_LINE4, "Track");
TextOut(0, LCD_LINE5, "Back");
}
if (Lnk == 1)
{
TextOut(0, LCD_LINE3, "NXC");
TextOut(0, LCD_LINE4, "Track", DRAW_OPT_INVERT);
TextOut(0, LCD_LINE5, "Back");
}
if (Lnk == 2)
{
TextOut(0, LCD_LINE3, "NXC");
TextOut(0, LCD_LINE4, "Track");
TextOut(0, LCD_LINE5, "Back", DRAW_OPT_INVERT);
}
if (1 == ButtonCount(BTNLEFT,true))
{
  if (0 < Lnk)
  {
  Lnk = Lnk - 1;
  }
}
if (1 == ButtonCount(BTNRIGHT,true))
{
  if (2 > Lnk)
  {
  Lnk = Lnk + 1;
  }
}
Wait(15);
}
if (Lnk == 0)
{
NXC(Note, "Audio", Octave);
}
if (Lnk == 1)
{
Track(Note, "Audio", Octave);
}
if (Lnk == 2)
{
goto MenuM;
}
}
if (LinkNumber == 2)
{
int LinkNumber;
while (false == ButtonCount(BTNCENTER,true))
{
TextOut(0, LCD_LINE1, "Generate", true);
if (LinkNumber == 0)
{
TextOut(0, LCD_LINE3, "Random", DRAW_OPT_INVERT);
TextOut(0, LCD_LINE4, "Wave");
}
if (LinkNumber == 1)
{
TextOut(0, LCD_LINE3, "Random");
TextOut(0, LCD_LINE4, "Wave", DRAW_OPT_INVERT);
}
if (1 == ButtonCount(BTNLEFT,true))
{
  if (0 < LinkNumber)
  {
  LinkNumber = LinkNumber - 1;
  }
}
if (1 == ButtonCount(BTNRIGHT,true))
{
  if (1 > LinkNumber)
  {
  LinkNumber = LinkNumber + 1;
  }
}
Wait(15);
}
int Cont = 0, Rand;
ClearScreen();
if (LinkNumber == 0)
{
while (Cont < ArrayLen(Note))
{
Rand = Random(64);
if (Rand == 0)
{
Rand = 1;
}
Note[Cont] = Rand;
LineOut(Cont, 0, Cont, Note[Cont]);
Cont++;
Wait(50);
}
}

// Tests

else
{
int ii = 0, f;
float Syn = 0;
while (ii < ArrayLen(Note))
{
f = trunc(sin(Syn));
Note(ii) = f;
Syn = Syn + 0.1;
ii++;
LineOut(ii, 0, ii, Note[ii]);
Wait(50);
}
}

// End Tests

}
}
LineOut(Curser, (Note[Curser] + 8), Curser, 64, true);
L = 0;

// Render

while (L < 100 && 0 == Sensor(S1))
{
LineOut(L, 0, L, Note[L]);
L++;
}
if (ButtonCount(BTNLEFT, true) && Curser > 0)
{
Curser--;
}
if (ButtonCount(BTNRIGHT, true) && Curser < 99)
{
Curser++;
}
if (ButtonCount(BTNEXIT, true) && Note[Curser] > 0)
{
Note[Curser]--;
}
if (ButtonPressed(BTNCENTER, true) && Note[Curser] < 63)
{
Note[Curser]++;
}

Wait(50);
}

// Play

if (Note[0] > 0)
{
C2 = 0;
while (1 == Sensor(S1))
{
L = 0;
RectOut(0, 0, 100, 64, DRAW_OPT_FILL_SHAPE);
LineOut(C2, (Note[C2] + 8), C2, 64, DRAW_OPT_CLEAR);
while (L < 100 && 1 == Sensor(S1))
{
LineOut(L, 0, L, Note[L], DRAW_OPT_CLEAR);
L++;
}
PlayTone((Note[C2] + Octave), 320);
Wait(50);
C2++;
if (C2 > ArrayLen(Note) - 1 || Note[C2] == 0)
{
C2 = 0;
}
}
}
}
}
-Dud.
2Labz.com, My Website
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: Code/Bug Trouble

Post by mattallen37 »

Two things (unrelated to your question).

1. Indent your code so it can be read.
2. Don't use a spoiler for just a codebox.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Code/Bug Trouble

Post by muntoo »

... Wait, what's the question? (You said, "I wonder what's causing this.")

Also, "I'm having trouble" is not a sufficient enough description. Is it a compiler error? Is it a runtime error? A bug? What are the effects of this bug?
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: Code/Bug Trouble

Post by dudmaster »

It doesn't compile. I don't think "Note[ii] = f;" is a problem, but when I remove it, it works.
2Labz.com, My Website
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Code/Bug Trouble

Post by muntoo »

NXC() is not a function. (It's not "defined"/declared.)

Plus, "NXC" is not a good name for a function.
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: Code/Bug Trouble

Post by dudmaster »

Sorry. That's in AudioLib.nxc
2Labz.com, My Website
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: Code/Bug Trouble

Post by HaWe »

I still can't see your code yet.
And I agree, NXC() is not a good name for a function.
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: Code/Bug Trouble

Post by m-goldberg »

Your program doesn't have 'Note[ii] = f;', it has 'Note(ii) = f;'. I think the compiler has every right to complain about a reference to an undefined function.
Regards, Morton
muntoo
Posts: 834
Joined: 01 Oct 2010, 02:54
Location: Your Worst Nightmare
Contact:

Re: Code/Bug Trouble

Post by muntoo »

dudmaster wrote:Sorry. That's in AudioLib.nxc
...Then why haven't you #included it?
Image

Commit to LEGO Mindstorms Robotics Stack Exchange:
bit.ly/MindstormsSE


Commit to LEGO Stack Exchange: bit.ly/Area51LEGOcommit
dudmaster
Posts: 171
Joined: 06 Oct 2010, 02:38
Location: Texas, Santa Fe
Contact:

Re: Code/Bug Trouble

Post by dudmaster »

I removed that for posting.
2Labz.com, My Website
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests