Author Topic: Does not name a type even though I made a typedef  (Read 3250 times)

Offline Zipdox

  • High Voltage Technician
  • ***
  • Posts: 143
  • Karma: +1/-0
    • View Profile
    • Zipdox
Does not name a type even though I made a typedef
« on: March 27, 2020, 11:58:01 PM »
For some reason I can't compile this code for Arduino.
Code: [Select]
#include <MIDI.h>

#define samplingRate 62500
#define maxPlayingNotes 2

MIDI_CREATE_DEFAULT_INSTANCE();

float midiFrequency(float note){
  return 440*(pow(2, (note-69)/12));
}

typedef struct {
    byte pitch;
    int onTime;
    int offTime;
    int hasBeenOn;
} Note;

Note getNoteTimes(byte pitch, float dutyCycle){
  float period = samplingRate/midiFrequency(pitch);
  Note finalNote = {pitch, round(dutyCycle*period), round((1-dutyCycle)*period), 0};
  return finalNote;
}

volatile Note playingNotes[maxPlayingNotes];



void handleNoteOn(byte channel, byte pitch, byte velocity){
    for(int i = 0; i < maxPlayingNotes; i++){
        if(playingNotes[i].onTime == 0){ // 0 onTime means this note isn't in use
            playingNotes[i] = getNoteTimes(pitch, 0.1);
            break;
        }
    }
    digitalWrite(13, HIGH);
}

void handleNoteOff(byte channel, byte pitch, byte velocity){
    for(int i = 0; i < maxPlayingNotes; i++){
        if(playingNotes[i].pitch == pitch){
            playingNotes[i] = {0,0,0,0}; // 0 onTime means it doesn't play
        }
    }
    digitalWrite(13, LOW);
}

//void handlePitchBend(byte channel, int bend){
//  float bendfactor = (1+ (float) bend/8190);
//  float dutyCycle = 0.1;
//  for(int i = 0; i < maxPlayingNotes; i++){
//      if(playingNotes[i].onTime == 0) continue;
//      float period = samplingRate/(bendfactor * midiNotes[playingNotes[i].pitch]);
//      playingNotes[i].onTime = round(dutyCycle*period);
//      playingNotes[i].offTime = round((1-dutyCycle)*period);
//  }
//}






void setup(){
    for(int i = 0; i<(sizeof(playingNotes)/sizeof(playingNotes[0])); i++){
        playingNotes[i] = {0,0,0,0};
    }
//  playingNotes[0] = getNoteTimes(261.6, 0.1);
//  playingNotes[1] = getNoteTimes(329.6, 0.1);
//  playingNotes[2] = getNoteTimes(392.0, 0.1);
    pinMode(9, OUTPUT);
    pinMode(13, OUTPUT);

  cli(); //stop interrupts
//  TCCR2A = 0; // set Timer/Counter Control Registers (TCCR2A/B) to 0
  TCCR2B = 0;
 
  OCR2A = 0; // = 16000000 / (freq*prescaler) - 1 (must be <256)
  // turn on CTC mode
  TCCR2A |= (1 << WGM21);
  // Set CS01 and CS00 bits for 64 prescaler
  TCCR2B |= (1 << CS20);
  // enable timer compare interrupt
  TIMSK2 |= (1 << OCIE2A);
  sei(); //allow interrupts


  MIDI.setHandleNoteOn(handleNoteOn);
  MIDI.setHandleNoteOff(handleNoteOff);
//  MIDI.setHandlePitchBend(handlePitchBend);
  MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop(){
    MIDI.read();
}

volatile bool shouldPlay;
ISR(TIMER2_COMPA_vect){

  shouldPlay = false;
 
  for(int i = 0; i < maxPlayingNotes; i++){
    if(playingNotes[i].onTime == 0) continue;
    playingNotes[i].hasBeenOn++;
    if(playingNotes[i].hasBeenOn > playingNotes[i].onTime){
        playingNotes[i].hasBeenOn = -playingNotes[i].offTime;
    }
    if(playingNotes[i].hasBeenOn >= 0){
        shouldPlay = true;
    }
  }

  if(shouldPlay){
    PORTB |= 1 << 1;
  }else{
    PORTB &= ~(1 << 1);
  }





 
//  byte ^= 1 << bit_to_flip;
//  byte &= ~(1 << bit_to_clear);
//  byte |= 1 << bit_to_set;
}

polyphonic_midi_interrupter_pitchbend:19:1: error: 'Note' does not name a type; did you mean 'tone'?
 Note getNoteTimes(byte pitch, float dutyCycle){
 ^~~~
 tone
exit status 1
'Note' does not name a type; did you mean 'tone'?

Offline klugesmith

  • High Voltage Senior
  • *****
  • Posts: 688
  • Karma: +22/-0
    • View Profile
Re: Does not name a type even though I made a typedef
« Reply #1 on: March 28, 2020, 04:14:17 AM »
A C instructor I am not. 

Am kind of rusty with typedefs, but don't think you need one here.  What if you skip "typedef" ?

The way you said it,  Note seems to be an instance of a nameless kind of struct.
Don't we need to say something like:

struct Note {
 int x;
 int y;
};
struct Note Note1;
struct Note foo();
int bar( struct Note z );

Maybe the typedef lets you later say Note instead of struct Note, but I'm out of my element here.  STFI!

Here's one reference found immediately with DuckDuckGo:
https://stackoverflow.com/questions/9653072/return-a-struct-from-a-function-in-c
« Last Edit: March 28, 2020, 04:33:06 AM by klugesmith »

Offline Zipdox

  • High Voltage Technician
  • ***
  • Posts: 143
  • Karma: +1/-0
    • View Profile
    • Zipdox
Re: Does not name a type even though I made a typedef
« Reply #2 on: March 28, 2020, 01:29:53 PM »
A C instructor I am not. 

Am kind of rusty with typedefs, but don't think you need one here.  What if you skip "typedef" ?

The way you said it,  Note seems to be an instance of a nameless kind of struct.
Don't we need to say something like:

struct Note {
 int x;
 int y;
};
struct Note Note1;
struct Note foo();
int bar( struct Note z );

Maybe the typedef lets you later say Note instead of struct Note, but I'm out of my element here.  STFI!

Here's one reference found immediately with DuckDuckGo:
https://stackoverflow.com/questions/9653072/return-a-struct-from-a-function-in-c

It's really weird because it used to work before, but somehow now that I changed some other code it no longer does.

Offline SteveN87

  • High Voltage Experimenter
  • **
  • Posts: 53
  • Karma: +4/-0
  • FPGA, Software Defined Radio, HV (mainly flyback)
    • View Profile
Re: Does not name a type even though I made a typedef
« Reply #3 on: March 28, 2020, 03:27:54 PM »
Does it work if you add a struct tag? e.g.:

Code: [Select]
typedef struct Note_t {
    byte pitch;
    int onTime;
    int offTime;
    int hasBeenOn;
} Note;

Offline Zipdox

  • High Voltage Technician
  • ***
  • Posts: 143
  • Karma: +1/-0
    • View Profile
    • Zipdox
Re: Does not name a type even though I made a typedef
« Reply #4 on: March 28, 2020, 04:47:45 PM »
Does it work if you add a struct tag? e.g.:

Code: [Select]
typedef struct Note_t {
    byte pitch;
    int onTime;
    int offTime;
    int hasBeenOn;
} Note;

No it doesn't. I also tried doing struct and typedef separately and it also doesn't work. I believe this might be a bug in the compiler because when I tried moving functions around it gave very weird output, there were words joined without spaces ans it was all very confusing. I may file a bug report later.

Offline klugesmith

  • High Voltage Senior
  • *****
  • Posts: 688
  • Karma: +22/-0
    • View Profile
Re: Does not name a type even though I made a typedef
« Reply #5 on: March 28, 2020, 06:27:49 PM »
One rite of passage for coders is finding their first compiler bug,
where correct source code does not compile or behaves wrong.

Offline SteveN87

  • High Voltage Experimenter
  • **
  • Posts: 53
  • Karma: +4/-0
  • FPGA, Software Defined Radio, HV (mainly flyback)
    • View Profile
Re: Does not name a type even though I made a typedef
« Reply #6 on: March 28, 2020, 06:45:21 PM »
Have they changed the default C standard revision to C18? (Maybe knock it down to C11 if so.)

Offline T3sl4co1l

  • High Voltage Technician
  • ***
  • Posts: 174
  • Karma: +9/-0
    • View Profile
    • Seven Transistor Labs
Re: Does not name a type even though I made a typedef
« Reply #7 on: March 28, 2020, 10:15:20 PM »
Probably a missing semicolon somewhere then.

Also FYI, declarations are usually placed in headers so they are declared at the top right away; doesn't matter if you're only using it in just one file but it is a more organized style.

Tim

High Voltage Forum

Re: Does not name a type even though I made a typedef
« Reply #7 on: March 28, 2020, 10:15:20 PM »

 


* Recent Topics and Posts

post Re: Re-chargeable 1.5 volt lithium ion AAA batteries
[General Chat]
MRMILSTAR
Today at 04:47:35 AM
post Re: Re-chargeable 1.5 volt lithium ion AAA batteries
[General Chat]
davekni
Today at 03:59:27 AM
post Re: Kaizer VTTC 1
[Vacuum Tube Tesla Coils (VTTC)]
MRMILSTAR
March 28, 2024, 09:15:11 PM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
Alberto
March 28, 2024, 01:01:12 PM
post Re: Big Coil Build Log
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
March 28, 2024, 05:47:34 AM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
davekni
March 28, 2024, 04:45:07 AM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
MRMILSTAR
March 28, 2024, 04:18:27 AM
post Push Pull VTTC
[Vacuum Tube Tesla Coils (VTTC)]
janno288
March 28, 2024, 01:10:08 AM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
Alberto
March 27, 2024, 10:54:52 PM
post Re: CM400 Induction Heater
[Electronic Circuits]
markus
March 27, 2024, 11:53:42 AM
post Re: OCD Triggering Early + Low Output
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
March 27, 2024, 05:14:36 AM
post Re: Is the UD2.7C under voltage lock out basically worthless?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
March 27, 2024, 04:47:48 AM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
March 27, 2024, 04:41:59 AM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
alan sailer
March 27, 2024, 12:04:34 AM
post Re: Super flat QCW simulation (does this look reasonable?)
[Dual Resonant Solid State Tesla coils (DRSSTC)]
toooldforthis
March 26, 2024, 11:08:14 PM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 26, 2024, 11:07:20 PM
post Re: Is the UD2.7C under voltage lock out basically worthless?
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 26, 2024, 10:46:29 PM
post OCD Triggering Early + Low Output
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Saattvik24
March 26, 2024, 09:03:43 PM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
alan sailer
March 26, 2024, 08:46:59 PM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
March 26, 2024, 05:02:18 PM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
alan sailer
March 26, 2024, 03:16:03 PM
post Re: CM400 Induction Heater
[Electronic Circuits]
Anders Mikkelsen
March 26, 2024, 01:41:49 PM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 26, 2024, 04:48:22 AM
post Re: Re-chargeable 1.5 volt lithium ion AAA batteries
[General Chat]
MRMILSTAR
March 26, 2024, 04:16:37 AM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
March 26, 2024, 04:16:24 AM
post Re: Smoke Screen Machine Protect 950 XP - Teardown of a Smoke Cannon!
[Electronic Circuits]
davekni
March 26, 2024, 04:13:02 AM
post Re: CM400 Induction Heater
[Electronic Circuits]
davekni
March 26, 2024, 04:00:43 AM
post Re: Re-chargeable 1.5 volt lithium ion AAA batteries
[General Chat]
davekni
March 26, 2024, 03:19:18 AM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
thedoc298
March 26, 2024, 01:50:42 AM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
March 25, 2024, 08:05:02 PM
post Re: Smoke Screen Machine Protect 950 XP - Teardown of a Smoke Cannon!
[Electronic Circuits]
Mads Barnkob
March 25, 2024, 07:41:29 PM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
alan sailer
March 25, 2024, 06:45:46 PM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
March 25, 2024, 05:44:25 PM
post Re: CM400 Induction Heater
[Electronic Circuits]
Anders Mikkelsen
March 25, 2024, 04:47:17 PM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
alan sailer
March 25, 2024, 04:27:22 PM
post Re-chargeable 1.5 volt lithium ion AAA batteries
[General Chat]
MRMILSTAR
March 25, 2024, 03:57:34 PM
post Re: CM400 Induction Heater
[Electronic Circuits]
markus
March 25, 2024, 02:06:41 PM
post Re: Odd MOSFET Driver Behavior
[Solid State Tesla Coils (SSTC)]
KrisPringle
March 25, 2024, 04:43:25 AM
post Re: Odd MOSFET Driver Behavior
[Solid State Tesla Coils (SSTC)]
davekni
March 25, 2024, 02:39:40 AM
post Re: Odd MOSFET Driver Behavior
[Solid State Tesla Coils (SSTC)]
KrisPringle
March 25, 2024, 12:47:09 AM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
Alberto
March 24, 2024, 07:36:32 PM
post Re: My completed 14-stage Cockroft-Walton voltage multiplier
[Voltage Multipliers]
Alberto
March 24, 2024, 07:27:24 PM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
MRMILSTAR
March 24, 2024, 04:25:23 AM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
Alberto
March 23, 2024, 10:47:35 PM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
MRMILSTAR
March 23, 2024, 09:30:21 PM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
Alberto
March 23, 2024, 04:34:31 PM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
MRMILSTAR
March 23, 2024, 03:04:25 PM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
Alberto
March 23, 2024, 01:38:34 PM
post Re: capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
MRMILSTAR
March 23, 2024, 04:20:03 AM
post Re: Welcome new members, come say hello and tell a little about yourself :)
[General Chat]
davekni
March 23, 2024, 12:54:30 AM
post Re: Smoke Screen Machine Protect 950 XP - Teardown of a Smoke Cannon!
[Electronic Circuits]
davekni
March 23, 2024, 12:05:57 AM
post capacitor and diodes. Voltage values for a CW
[Voltage Multipliers]
Alberto
March 22, 2024, 11:45:03 PM
post Re: Welcome new members, come say hello and tell a little about yourself :)
[General Chat]
OmGigaTron
March 22, 2024, 11:30:09 PM
post Smoke Screen Machine Protect 950 XP - Teardown of a Smoke Cannon!
[Electronic Circuits]
Mads Barnkob
March 22, 2024, 10:20:35 PM
post Re: Where's all this voltage coming from?
[Spark Gap Tesla Coils (SGTC)]
Benbmw
March 22, 2024, 09:21:13 PM
post Re: What actually kills MOSFETs?
[Beginners]
AstRii
March 22, 2024, 03:37:11 PM
post What actually kills MOSFETs?
[Beginners]
FPS
March 22, 2024, 05:09:20 AM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 22, 2024, 03:57:54 AM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
March 22, 2024, 02:59:25 AM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 21, 2024, 06:31:42 PM
post Re: 2x Panasonic Inverter Microwaves - what to salvage, dangers?
[General Chat]
rikkitikkitavi
March 21, 2024, 03:08:01 PM
post Re: [WTS] IGBT, Ferrite, Capacitors, Tools, PSU, Industrial components and parts
[Sell / Buy / Trade]
Mads Barnkob
March 21, 2024, 01:37:32 PM
post Re: Difference between these transformers
[Transformer (Ferrite Core)]
Alberto
March 21, 2024, 11:42:07 AM
post Re: Phase Lead Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
March 21, 2024, 04:09:14 AM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 21, 2024, 02:15:31 AM
post My Homemade Structural Analysis X-Ray Machine
[X-ray]
Luca c.
March 21, 2024, 01:35:40 AM
post Re: Phase Lead Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Saattvik24
March 20, 2024, 10:40:00 PM
post Re: Difference between these transformers
[Transformer (Ferrite Core)]
Mads Barnkob
March 20, 2024, 08:03:41 PM
post Re: 2x Panasonic Inverter Microwaves - what to salvage, dangers?
[General Chat]
Mads Barnkob
March 20, 2024, 07:51:57 PM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
March 20, 2024, 10:39:47 AM
post Re: Phase Lead Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
davekni
March 20, 2024, 04:09:59 AM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 20, 2024, 01:13:23 AM
post Re: Phase Lead Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Keybored
March 20, 2024, 12:45:16 AM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
March 20, 2024, 12:30:30 AM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 19, 2024, 11:12:24 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
March 19, 2024, 09:47:49 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
March 19, 2024, 09:44:19 PM
post Phase Lead Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Saattvik24
March 19, 2024, 06:52:09 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
March 19, 2024, 05:02:44 PM
post Re: Welcome new members, come say hello and tell a little about yourself :)
[General Chat]
Mads Barnkob
March 19, 2024, 05:01:41 PM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
March 19, 2024, 04:31:02 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Mads Barnkob
March 19, 2024, 03:59:54 PM
post Re: Benjamin's DRSSTC 2 in progress
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Benjamin Lockhart
March 19, 2024, 06:41:39 AM
post Re: Welcome new members, come say hello and tell a little about yourself :)
[General Chat]
davekni
March 19, 2024, 04:05:49 AM
post Re: Welcome new members, come say hello and tell a little about yourself :)
[General Chat]
OmGigaTron
March 18, 2024, 09:08:35 PM
post Re: Can I Trust This Super Cheap Site?
[General Chat]
2020-Man
March 18, 2024, 09:07:35 PM
post Re: Can I Trust This Super Cheap Site?
[General Chat]
Twospoons
March 18, 2024, 08:57:06 PM
post Re: Can I Trust This Super Cheap Site?
[General Chat]
MRMILSTAR
March 18, 2024, 03:51:33 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
March 18, 2024, 02:59:46 PM
post Re: 160mm DRSSTC II project | Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
Late
March 18, 2024, 02:33:25 PM
post Can I Trust This Super Cheap Site?
[General Chat]
2020-Man
March 18, 2024, 11:02:12 AM
post Re: Where's all this voltage coming from?
[Spark Gap Tesla Coils (SGTC)]
Twospoons
March 18, 2024, 02:36:11 AM
post Re: Best forum for vacuum tube amplifiers?
[General Chat]
Mads Barnkob
March 17, 2024, 07:42:55 PM
post Re: 2x Panasonic Inverter Microwaves - what to salvage, dangers?
[General Chat]
Michelle_
March 17, 2024, 04:15:14 PM
post Re: 2x Panasonic Inverter Microwaves - what to salvage, dangers?
[General Chat]
Michelle_
March 17, 2024, 05:05:04 AM
post Re: Where's all this voltage coming from?
[Spark Gap Tesla Coils (SGTC)]
davekni
March 17, 2024, 04:50:51 AM
post Re: 2x Panasonic Inverter Microwaves - what to salvage, dangers?
[General Chat]
Twospoons
March 17, 2024, 04:45:17 AM
post 2x Panasonic Inverter Microwaves - what to salvage, dangers?
[General Chat]
Michelle_
March 17, 2024, 04:17:51 AM
post Where's all this voltage coming from?
[Spark Gap Tesla Coils (SGTC)]
Terry
March 17, 2024, 01:29:32 AM
post Re: DRSSTC Questions
[Dual Resonant Solid State Tesla coils (DRSSTC)]
flyingperson23
March 17, 2024, 12:33:06 AM

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 
SimplePortal 2.3.6 © 2008-2014, SimplePortal