hello, I tried to compile as described on 22Aug by giuliomoro, but running the last line (make -C ~/Bela PROJECT=HeavyProjectName COMPILER=gcc run) I got this error:
make: *** No rule to make target `run'. Stop.
I noticed the /Bela/projects/HeavyProjectName has been created and populated by a bunch of folders, but this is just the source code, shouldnt I be taking a single .cpp file or something so I can upload it to bela with the IDE? (sorry I am not a programmer and feel totally lost at sea...) btw I am on a Mac.
any help would be very appreciated!

I take it you are referring to the following instructions:

giuliomoro

python2.7 ~/hvcc/hvcc.py /path/to/source/project/_main.pd -o /tmp/hvtmp -n bela -g c
mkdir -p ~/Bela/projects/HeavyProjectName
rsync -av ~/Bela/scripts/hvresources/render.cpp /tmp/hvtmp/c/* ~/Bela/projects/HeavyProjectName/
make -C ~/Bela PROJECT=HeavyProjectName COMPILER=gcc run

These are meant to be run directly on the board after installing the needed tools as explained earlier in that post (those tools are already available in Bela images version v0.3.6 or above).

It sounds like you are running them on the host computer just now?

There are also instructions to be run on the host computer, just a few posts down: see here https://forum.bela.io/d/636-heavy-pd-and-enzienaudio/12 . Running them on the host makes the setup easier and the compilation faster.

    giuliomoro
    Grazie mille Giulio!
    Yes, I was running them on the host computer (!!) will try the correct instructions as soon as life permits.
    thanks again for the reply,
    C.

    7 days later

    Thank you so much for the clarification Giulio,
    I finally managed to compile the heavy file!!

    8 days later

    As of today, I created a master-bela branch on https://github.com/giuliomoro/hvcc where I merged a couple of fixes for MIDI (now MIDI outputs work) and for Xenomai (now you can compile with clang instead of gcc, so compilation time can get significantly faster). I will try to keep this as up to date as possible (that is: every fix I know of will go in there), so I'd recommend everyone on Bela to use this instead of https://github.com/enzienaudio/hvcc. However, please note that I am not the new maintainer of hvcc, so please don't ask for features, as they will not be implemented (by me).

    3 months later

    How do you get a PD patch compiled using RebelTech's on-line Heavy compiler to run on the Bela?

    The code it's generated seems to be missing a render.cpp file. Does it need one? And what should be in it?

    I have never used it, I think you may need this, however it depends on the "patch name" given to the compiler. If the patch name is not "bela", then the included file Heavy_bela.h will not exist.
    (my recommendations to use the Heavy compiler without relying on an online compiler are above.)

    Hi Giuliomoro, thanks for replying!

    I tried following your instructions. I got the render.cpp file you mentioned in your reply just now and made a Bela/scripts/hvresources directory and put it in there.

    It looked like it nearly worked but had the following error while compiling:

    /root/Bela/projects/WindchimeHeavy/render.cpp:85:13: error: ‘class Midi’ has no member named ‘isInputEnabled’
        midi[n]->isInputEnabled() ? "x" : "_",
                 ^
    /root/Bela/projects/WindchimeHeavy/render.cpp:86:13: error: ‘class Midi’ has no member named ‘isOutputEnabled’
        midi[n]->isOutputEnabled() ? "x" : "_",
                 ^
    /root/Bela/projects/WindchimeHeavy/render.cpp: In function ‘Midi* openMidiDevice(std::string, bool, bool)’:
    /root/Bela/projects/WindchimeHeavy/render.cpp:100:14: error: ‘class Midi’ has no member named ‘isOutputEnabled’
      if(newMidi->isOutputEnabled())
                  ^
    /root/Bela/projects/WindchimeHeavy/render.cpp:105:14: error: ‘class Midi’ has no member named ‘isInputEnabled’
      if(newMidi->isInputEnabled())
                  ^
    /root/Bela/projects/WindchimeHeavy/render.cpp:110:15: error: ‘class Midi’ has no member named ‘isInputEnabled’
      if(!newMidi->isInputEnabled() && !newMidi->isOutputEnabled())
                   ^
    /root/Bela/projects/WindchimeHeavy/render.cpp:110:45: error: ‘class Midi’ has no member named ‘isOutputEnabled’
      if(!newMidi->isInputEnabled() && !newMidi->isOutputEnabled())

    I've commented out the lines in render.cpp that reference isInputEnabled and isOutputEnabled and it seems to be compiling now.

    I'm guessing I've got some kind of version mismatch between this render.cpp and what I've got installed on the Bela.

    On your board,at the path /root/Bela/scripts/hvresources/render.cpp you should have a wrapper for heavy that should be compatible with your version of the Bela core core.

    7 months later

    giuliomoro Thanks for your instructions!
    I am having some trouble installing the files from the requirements.txt on my laptop (I am working with ubuntu 18.04) could you help me?

    I have python 2.7 and 3.6 on my laptop. (I set 2.7 as default).

    i get the following errors:

     ERROR: Command errored out with exit status 1:
     command: /home/yannick/anaconda3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c2abhcn_/enum/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c2abhcn_/enum/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-c2abhcn_/enum/pip-egg-info
         cwd: /tmp/pip-install-c2abhcn_/enum/
    Complete output (11 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/yannick/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 6, in <module>
        import distutils.core
      File "/home/yannick/anaconda3/lib/python3.6/distutils/core.py", line 16, in <module>
        from distutils.dist import Distribution
      File "/home/yannick/anaconda3/lib/python3.6/distutils/dist.py", line 9, in <module>
        import re
      File "/home/yannick/anaconda3/lib/python3.6/re.py", line 142, in <module>
        class RegexFlag(enum.IntFlag):
    AttributeError: module 'enum' has no attribute 'IntFlag'
    ----------------------------------------

    ERROR: Command errored out with exit status 1: python setup.py egg_info

    i tried installing jinja2 separately, it installs succesfully, but I still get an error:

    ERROR: flask 1.0.2 has requirement Jinja2>=2.10, but you'll have jinja2 2.7.3 which is incompatible. (do you know if I could just try to upgrade jinja2 to a higher version, or I need to create a situation where I can run 2.7.3?)

      I actually don't know. This seems python dependency hell ... I guess my best recommendation would be nuke the whole thing and start over.

      BUT let's try to make some sense of it. All the errors refer to python3.6, which makes me suspect there is something wrong in your path or default python? Maybe this could be a good starting point to investigate.

      yannick (do you know if I could just try to upgrade jinja2 to a higher version, or I need to create a situation where I can run 2.7.3?)

      I have no idea!

      Sorry I can't be of much help.

      5 days later

      giuliomoro

      thanks for your reply! so i restarted the whole process. on the board, the compiler seems to be running fine, i successfully compiled the basic (example) pd patch to the Bela. but in the project i'm workig on, i still get a lot of errors in the link process, (almost all of them got something to do with the render.cpp file, "undefined reference to 'libpd_...') i have recently updated my bela image to 0.3.7a .

      root@bela:~/hvcc# make -C ~/Bela PROJECT=NonagonBar_HVCC COMPILER=gcc run
      make: Entering directory '/root/Bela'
      Killing old Bela process 4140
      Building HvMessage.c...
      /root/Bela/projects/NonagonBar_HVCC/HvMessage.c: In function 'msg_getHash':
      /root/Bela/projects/NonagonBar_HVCC/HvMessage.c:151:7: warning: dereferencing ty             pe-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
             return *((hv_uint32_t *) &f);
             ^~~~~~
       ...done
      
      Building HvControlVar.c...
       ...done
      
      Building HvTable.c...
       ...done
      
      Building HvMessagePool.c...
       ...done
      
      Building HvControlBinop.c...
       ...done
      
      Building HvControlCast.c...
       ...done
      
      Building HvControlDelay.c...
       ...done
      
      Building HvControlPack.c...
       ...done
      
      Building HvMessageQueue.c...
       ...done
      
      Building HvControlPrint.c...
       ...done
      
      Building HvUtils.c...
       ...done
      
      Building HvControlSlice.c...
       ...done
      
      Building HvLightPipe.c...
       ...done
      
      Building HvControlSystem.c...
       ...done
      
      Building render.cpp...
      /root/Bela/projects/NonagonBar_HVCC/render.cpp: In function 'void render(BelaCon             text*, void*)':
      /root/Bela/projects/NonagonBar_HVCC/render.cpp:533:28: warning: comparison betwe             en signed and unsigned integer expressions [-Wsign-compare]
        for(unsigned int n = 0; n < touchSensorMain.numSensors(); ++n)
                                ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /root/Bela/projects/NonagonBar_HVCC/render.cpp:636:20: warning: comparison betwe             en signed and unsigned integer expressions [-Wsign-compare]
         for(int n = 0; n < context->audioInChannels; ++n)
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
      /root/Bela/projects/NonagonBar_HVCC/render.cpp:646:20: warning: comparison betwe             en signed and unsigned integer expressions [-Wsign-compare]
         for(int n = 0; n < context->analogInChannels; ++n)
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
      /root/Bela/projects/NonagonBar_HVCC/render.cpp:719:20: warning: comparison betwe             en signed and unsigned integer expressions [-Wsign-compare]
         for(int n = 0; n < context->audioOutChannels; ++n)
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
      /root/Bela/projects/NonagonBar_HVCC/render.cpp:729:20: warning: comparison betwe             en signed and unsigned integer expressions [-Wsign-compare]
         for(int n = 0; n < context->analogOutChannels; ++n)
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ...done
      
      Building HeavyContext.cpp...
       ...done
      
      Building HvHeavy.cpp...
      /root/Bela/projects/NonagonBar_HVCC/HvHeavy.cpp:24:0: warning: ignoring #pragma              mark  [-Wunknown-pragmas]
       #pragma mark - Heavy Table
      
      /root/Bela/projects/NonagonBar_HVCC/HvHeavy.cpp:45:0: warning: ignoring #pragma              mark  [-Wunknown-pragmas]
       #pragma mark - Heavy Message
      
      /root/Bela/projects/NonagonBar_HVCC/HvHeavy.cpp:127:0: warning: ignoring #pragma              mark  [-Wunknown-pragmas]
       #pragma mark - Heavy Common
      
      /root/Bela/projects/NonagonBar_HVCC/HvHeavy.cpp:294:0: warning: ignoring #pragma              mark  [-Wunknown-pragmas]
       #pragma mark - Heavy Common
      
       ...done
      
      Building Heavy_bela.cpp...
       ...done
      
      Extracting dependencies of library Midi
      Extracting dependencies of library Scope
      Extracting dependencies of library Trill
      Extracting dependencies of library UdpServer
      Linking...
      /root/Bela/projects/NonagonBar_HVCC/build/render.o: In function `fdLoop(void*)':
      render.cpp:(.text+0x102): undefined reference to `sys_doio'
      /root/Bela/projects/NonagonBar_HVCC/build/render.o: In function `render':
      render.cpp:(.text+0x738): undefined reference to `libpd_start_message'
      render.cpp:(.text+0x750): undefined reference to `libpd_add_float'
      render.cpp:(.text+0x766): undefined reference to `libpd_finish_message'
      render.cpp:(.text+0x964): undefined reference to `libpd_sysrealtime'
      render.cpp:(.text+0x994): undefined reference to `libpd_pitchbend'
      render.cpp:(.text+0x9ae): undefined reference to `libpd_aftertouch'
      render.cpp:(.text+0x9c8): undefined reference to `libpd_programchange'
      render.cpp:(.text+0x9e6): undefined reference to `libpd_controlchange'
      render.cpp:(.text+0xa04): undefined reference to `libpd_polyaftertouch'
      render.cpp:(.text+0xa96): undefined reference to `libpd_noteon'
      render.cpp:(.text+0xab6): undefined reference to `libpd_noteon'
      render.cpp:(.text+0xfa4): undefined reference to `libpd_process_sys'
      render.cpp:(.text+0x14e8): undefined reference to `libpd_write_array'
      /root/Bela/projects/NonagonBar_HVCC/build/render.o: In function `cleanup':
      render.cpp:(.text+0x15ec): undefined reference to `libpd_closefile'
      /root/Bela/projects/NonagonBar_HVCC/build/render.o: In function `Bela_messageHoo             k(char const*, char const*, int, _atom*)':
      render.cpp:(.text+0x1798): undefined reference to `libpd_get_float'
      render.cpp:(.text+0x17c2): undefined reference to `libpd_is_float'
      render.cpp:(.text+0x1834): undefined reference to `libpd_is_float'
      render.cpp:(.text+0x183e): undefined reference to `libpd_get_float'
      render.cpp:(.text+0x186e): undefined reference to `libpd_is_symbol'
      render.cpp:(.text+0x1ff2): undefined reference to `libpd_get_symbol'
      /root/Bela/projects/NonagonBar_HVCC/build/render.o: In function `setup':
      render.cpp:(.text+0x23e2): undefined reference to `sys_getversion'
      render.cpp:(.text+0x2690): undefined reference to `libpd_blocksize'
      render.cpp:(.text+0x26ac): undefined reference to `libpd_set_printhook'
      render.cpp:(.text+0x26b6): undefined reference to `libpd_set_floathook'
      render.cpp:(.text+0x26c0): undefined reference to `libpd_set_messagehook'
      render.cpp:(.text+0x26ca): undefined reference to `libpd_set_noteonhook'
      render.cpp:(.text+0x26d4): undefined reference to `libpd_set_controlchangehook'
      render.cpp:(.text+0x26de): undefined reference to `libpd_set_programchangehook'
      render.cpp:(.text+0x26e8): undefined reference to `libpd_set_pitchbendhook'
      render.cpp:(.text+0x26f2): undefined reference to `libpd_set_aftertouchhook'
      render.cpp:(.text+0x26fc): undefined reference to `libpd_set_polyaftertouchhook'
      render.cpp:(.text+0x2706): undefined reference to `libpd_set_midibytehook'
      render.cpp:(.text+0x270a): undefined reference to `libpd_init'
      render.cpp:(.text+0x2714): undefined reference to `libpd_add_to_search_path'
      render.cpp:(.text+0x271e): undefined reference to `libpd_add_to_search_path'
      render.cpp:(.text+0x2734): undefined reference to `libpd_init_audio'
      render.cpp:(.text+0x2738): undefined reference to `get_sys_soundin'
      render.cpp:(.text+0x2740): undefined reference to `get_sys_soundout'
      render.cpp:(.text+0x274a): undefined reference to `libpd_start_message'
      render.cpp:(.text+0x2752): undefined reference to `libpd_add_float'
      render.cpp:(.text+0x2762): undefined reference to `libpd_finish_message'
      render.cpp:(.text+0x2776): undefined reference to `libpd_bind'
      render.cpp:(.text+0x278a): undefined reference to `libpd_bind'
      render.cpp:(.text+0x2796): undefined reference to `libpd_bind'
      render.cpp:(.text+0x279e): undefined reference to `libpd_openfile'
      render.cpp:(.text+0x27ba): undefined reference to `sys_dontmanageio'
      render.cpp:(.text+0x2892): undefined reference to `libpd_arraysize'
      render.cpp:(.text+0x28b2): undefined reference to `libpd_start_message'
      render.cpp:(.text+0x28be): undefined reference to `libpd_add_float'
      render.cpp:(.text+0x28c8): undefined reference to `libpd_finish_message'
      render.cpp:(.text+0x28d8): undefined reference to `libpd_float'
      /root/Bela/projects/NonagonBar_HVCC/build/render.o: In function `sendDigitalMess             age(bool, unsigned int, void*)':
      render.cpp:(.text+0x76): undefined reference to `libpd_float'
      collect2: error: ld returned 1 exit status
      Makefile.linkbela:42: recipe for target '/root/Bela/projects/NonagonBar_HVCC/Non             agonBar_HVCC' failed
      make[1]: *** [/root/Bela/projects/NonagonBar_HVCC/NonagonBar_HVCC] Error 1
      Makefile:526: recipe for target '/root/Bela/projects/NonagonBar_HVCC/NonagonBar_             HVCC' failed
      make: *** [/root/Bela/projects/NonagonBar_HVCC/NonagonBar_HVCC] Error 2
      make: Leaving directory '/root/Bela'                                                                                                                               

      (Please enclose the pasted log in ``` so that it gets formatted properly (I edited your message above accordingly).

      Can we see the content of the render.cpp file? I suspect that it is a render.cpp for libpd and not for heavy.

        giuliomoro Ok sorry for the messyness 😛 here is the pasted render.cpp file:

        #include <Bela.h>
        #include <DigitalChannelManager.h>
        #include <cmath>
        #include <stdio.h>
        #define PD_THREADED_IO
        #include <libpd/z_libpd.h>
        extern "C" {
        #include <libpd/s_stuff.h>
        };
        #include <libraries/UdpServer/UdpServer.h>
        #include <libraries/Midi/Midi.h>
        #include <libraries/Scope/Scope.h>
        #include <string>
        #include <sstream>
        #include <algorithm>
        // MODIFICATION START
        #include <libraries/Trill/Trill.h>
        //Trill touchSensor;
        Trill touchSensorMain;
        // how often to try to read the
        // cap sensors inputs. The cap sensor values are always sent to Pd once
        // per block, regardless.
        unsigned int touchSensorSleepIntervalUs = 5000;
        void readCapSensorLoop(void*)
        {
        	while(!gShouldStop)
        	{
        		//touchSensor.readI2C();
        		touchSensorMain.readI2C();
        		usleep(touchSensorSleepIntervalUs);
        	}
        }
        
        enum { minFirstDigitalChannel = 10 };
        static unsigned int gAnalogChannelsInUse;
        static unsigned int gDigitalChannelsInUse;
        static unsigned int gScopeChannelsInUse = 4;
        static unsigned int gLibpdBlockSize;
        static unsigned int gChannelsInUse;
        //static const unsigned int gFirstAudioChannel = 0;
        static unsigned int gFirstAnalogInChannel;
        static unsigned int gFirstAnalogOutChannel;
        static unsigned int gFirstDigitalChannel;
        static unsigned int gLibpdDigitalChannelOffset;
        static unsigned int gFirstScopeChannel;
        
        void Bela_userSettings(BelaInitSettings *settings)
        {
        	settings->uniformSampleRate = 1;
        	settings->interleave = 0;
        	settings->analogOutputsPersist = 0;
        }
        
        float* gInBuf;
        float* gOutBuf;
        #define PARSE_MIDI
        static std::vector<Midi*> midi;
        std::vector<std::string> gMidiPortNames;
        
        void dumpMidi()
        {
        	if(midi.size() == 0)
        	{
        		printf("No MIDI device enabled\n");
        		return;
        	}
        	printf("The following MIDI devices are enabled:\n");
        	printf("%4s%20s %3s %3s %s\n",
        			"Num",
        			"Name",
        			"In",
        			"Out",
        			"Pd channels"
        	      );
        	for(unsigned int n = 0; n < midi.size(); ++n)
        	{
        		printf("[%2d]%20s %3s %3s (%d-%d)\n",
        			n,
        			gMidiPortNames[n].c_str(),
        			midi[n]->isInputEnabled() ? "x" : "_",
        			midi[n]->isOutputEnabled() ? "x" : "_",
        			n * 16 + 1,
        			n * 16 + 16
        		);
        	}
        }
        
        Midi* openMidiDevice(std::string name, bool verboseSuccess = false, bool verboseError = false)
        {
        	Midi* newMidi;
        	newMidi = new Midi();
        	newMidi->readFrom(name.c_str());
        	newMidi->writeTo(name.c_str());
        #ifdef PARSE_MIDI
        	newMidi->enableParser(true);
        #else
        	newMidi->enableParser(false);
        #endif /* PARSE_MIDI */
        	if(newMidi->isOutputEnabled())
        	{
        		if(verboseSuccess)
        			printf("Opened MIDI device %s as output\n", name.c_str());
        	}
        	if(newMidi->isInputEnabled())
        	{
        		if(verboseSuccess)
        			printf("Opened MIDI device %s as input\n", name.c_str());
        	}
        	if(!newMidi->isInputEnabled() && !newMidi->isOutputEnabled())
        	{
        		if(verboseError)
        			fprintf(stderr, "Failed to open  MIDI device %s\n", name.c_str());
        		return nullptr;
        	} else {
        		return newMidi;
        	}
        }
        
        static unsigned int getPortChannel(int* channel){
        	unsigned int port = 0;
        	while(*channel > 16){
        		*channel -= 16;
        		port += 1;
        	}
        	if(port >= midi.size()){
        		// if the port number exceeds the number of ports available, send out
        		// of the first port
        		rt_fprintf(stderr, "Port out of range, using port 0 instead\n");
        		port = 0;
        	}
        	return port;
        }
        
        void Bela_MidiOutNoteOn(int channel, int pitch, int velocity) {
        	int port = getPortChannel(&channel);
        	rt_printf("noteout _ port: %d, channel: %d, pitch: %d, velocity %d\n", port, channel, pitch, velocity);
        	midi[port]->writeNoteOn(channel, pitch, velocity);
        }
        
        void Bela_MidiOutControlChange(int channel, int controller, int value) {
        	int port = getPortChannel(&channel);
        	rt_printf("ctlout _ port: %d, channel: %d, controller: %d, value: %d\n", port, channel, controller, value);
        	midi[port]->writeControlChange(channel, controller, value);
        }
        
        void Bela_MidiOutProgramChange(int channel, int program) {
        	int port = getPortChannel(&channel);
        	rt_printf("pgmout _ port: %d, channel: %d, program: %d\n", port, channel, program);
        	midi[port]->writeProgramChange(channel, program);
        }
        
        void Bela_MidiOutPitchBend(int channel, int value) {
        	int port = getPortChannel(&channel);
        	rt_printf("bendout _ port: %d, channel: %d, value: %d\n", port, channel, value);
        	midi[port]->writePitchBend(channel, value);
        }
        
        void Bela_MidiOutAftertouch(int channel, int pressure){
        	int port = getPortChannel(&channel);
        	rt_printf("touchout _ port: %d, channel: %d, pressure: %d\n", port, channel, pressure);
        	midi[port]->writeChannelPressure(channel, pressure);
        }
        
        void Bela_MidiOutPolyAftertouch(int channel, int pitch, int pressure){
        	int port = getPortChannel(&channel);
        	rt_printf("polytouchout _ port: %d, channel: %d, pitch: %d, pressure: %d\n", port, channel, pitch, pressure);
        	midi[port]->writePolyphonicKeyPressure(channel, pitch, pressure);
        }
        
        void Bela_MidiOutByte(int port, int byte){
        	rt_printf("port: %d, byte: %d\n", port, byte);
        	if(port > (int)midi.size()){
        		// if the port is out of range, redirect to the first port.
        		rt_fprintf(stderr, "Port out of range, using port 0 instead\n");
        		port = 0;
        	}
        	midi[port]->writeOutput(byte);
        }
        
        void Bela_printHook(const char *received){
        	rt_printf("%s", received);
        }
        
        static DigitalChannelManager dcm;
        
        void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){
        	libpd_float((const char*)receiverName, (float)state);
        //	rt_printf("%s: %d\n", (char*)receiverName, state);
        }
        
        void Bela_messageHook(const char *source, const char *symbol, int argc, t_atom *argv){
        	if(strcmp(source, "bela_setMidi") == 0){
        		int num[3] = {0, 0, 0};
        		for(int n = 0; n < argc && n < 3; ++n)
        		{
        			if(!libpd_is_float(&argv[n]))
        			{
        				fprintf(stderr, "Wrong format for Bela_setMidi, expected:[hw 1 0 0(");
        				return;
        			}
        			num[n] = libpd_get_float(&argv[n]);
        		}
        		std::ostringstream deviceName;
            deviceName << symbol << ":" << num[0] << "," << num[1] << "," << num[2];
        		printf("Adding Midi device: %s\n", deviceName.str().c_str());
        		Midi* newMidi = openMidiDevice(deviceName.str(), false, true);
        		if(newMidi)
        		{
        			midi.push_back(newMidi);
        			gMidiPortNames.push_back(deviceName.str());
        		}
        		dumpMidi();
        		return;
        	}
        	if(strcmp(source, "bela_setDigital") == 0){
        		// symbol is the direction, argv[0] is the channel, argv[1] (optional)
        		// is signal("sig" or "~") or message("message", default) rate
        		bool isMessageRate = true; // defaults to message rate
        		bool direction = 0; // initialize it just to avoid the compiler's warning
        		bool disable = false;
        		if(strcmp(symbol, "in") == 0){
        			direction = INPUT;
        		} else if(strcmp(symbol, "out") == 0){
        			direction = OUTPUT;
        		} else if(strcmp(symbol, "disable") == 0){
        			disable = true;
        		} else {
        			return;
        		}
        		if(argc == 0){
        			return;
        		} else if (libpd_is_float(&argv[0]) == false){
        			return;
        		}
        		int channel = libpd_get_float(&argv[0]) - gLibpdDigitalChannelOffset;
        		if(disable == true){
        			dcm.unmanage(channel);
        			return;
        		}
        		if(argc >= 2){
        			t_atom* a = &argv[1];
        			if(libpd_is_symbol(a)){
        				char *s = libpd_get_symbol(a);
        				if(strcmp(s, "~") == 0  || strncmp(s, "sig", 3) == 0){
        					isMessageRate = false;
        				}
        			}
        		}
        		dcm.manage(channel, direction, isMessageRate);
        		return;
        	}
        }
        
        void Bela_floatHook(const char *source, float value){
        	// let's make this as optimized as possible for built-in digital Out parsing
        	// the built-in digital receivers are of the form "bela_digitalOutXX" where XX is between gLibpdDigitalChannelOffset and (gLibpdDigitalCHannelOffset+gDigitalChannelsInUse)
        	static int prefixLength = 15; // strlen("bela_digitalOut")
        	if(strncmp(source, "bela_digitalOut", prefixLength)==0){
        		if(source[prefixLength] != 0){ //the two ifs are used instead of if(strlen(source) >= prefixLength+2)
        			if(source[prefixLength + 1] != 0){
        				// quickly convert the suffix to integer, assuming they are numbers, avoiding to call atoi
        				int receiver = ((source[prefixLength] - 48) * 10);
        				receiver += (source[prefixLength+1] - 48);
        				unsigned int channel = receiver - gLibpdDigitalChannelOffset; // go back to the actual Bela digital channel number
        				if(channel < gDigitalChannelsInUse){ //number of digital channels
        					dcm.setValue(channel, value);
        				}
        			}
        		}
        	}
        }
        
        
        
        std::vector<std::string> gReceiverInputNames;
        std::vector<std::string> gReceiverOutputNames;
        void generateDigitalNames(unsigned int numDigitals, unsigned int libpdOffset, std::vector<std::string>& receiverInputNames, std::vector<std::string>& receiverOutputNames)
        {
        	std::string inBaseString = "bela_digitalIn";
        	std::string outBaseString = "bela_digitalOut";
        	for(unsigned int i = 0; i<numDigitals; i++)
        	{
        		receiverInputNames.push_back(inBaseString + std::to_string(i+libpdOffset));
        		receiverOutputNames.push_back(outBaseString + std::to_string(i+libpdOffset));
        	}
        }
        
        void printDigitalNames(std::vector<std::string>& receiverInputNames, std::vector<std::string>& receiverOutputNames)
        {
        	printf("DIGITAL INPUTS\n");
        	for(unsigned int i=0; i<gDigitalChannelsInUse; i++)
        		printf("%s\n", receiverInputNames[i].c_str());
        	printf("DIGITAL OUTPUTS\n");
        	for(unsigned int i=0; i<gDigitalChannelsInUse; i++)
        		printf("%s\n", receiverOutputNames[i].c_str());
        }
        
        static char multiplexerArray[] = {"bela_multiplexer"};
        static int multiplexerArraySize = 0;
        static bool pdMultiplexerActive = false;
        
        #ifdef PD_THREADED_IO
        void fdLoop(void* arg){
        	while(!gShouldStop){
        		sys_doio();
        		usleep(3000);
        	}
        }
        #endif /* PD_THREADED_IO */
        
        Scope scope;
        float* gScopeOut;
        void* gPatch;
        bool gDigitalEnabled = 0;
        
        bool setup(BelaContext *context, void *userData)
        {
        	// Check Pd's version
        	int major, minor, bugfix;
        	sys_getversion(&major, &minor, &bugfix);
        	printf("Running Pd %d.%d-%d\n", major, minor, bugfix);
        	// We requested in Bela_userSettings() to have uniform sampling rate for audio
        	// and analog and non-interleaved buffers.
        	// So let's check this actually happened
        	if(context->analogSampleRate != context->audioSampleRate)
        	{
        		fprintf(stderr, "The sample rate of analog and audio must match. Try running with --uniform-sample-rate\n");
        		return false;
        	}
        	if(context->flags & BELA_FLAG_INTERLEAVED)
        	{
        		fprintf(stderr, "The audio and analog channels must be interleaved.\n");
        		return false;
        	}
        
        	if(context->digitalFrames > 0 && context->digitalChannels > 0)
        		gDigitalEnabled = 1;
        
        	// add here other devices you need
        	gMidiPortNames.push_back("hw:1,0,0");
        	//gMidiPortNames.push_back("hw:0,0,0");
        	//gMidiPortNames.push_back("hw:1,0,1");
        
        	scope.setup(gScopeChannelsInUse, context->audioSampleRate);
        	gScopeOut = new float[gScopeChannelsInUse];
        
        	// Check first of all if the patch file exists. Will actually open it later.
        	char file[] = "_main.pd";
        	char folder[] = "./";
        	unsigned int strSize = strlen(file) + strlen(folder) + 1;
        	char* str = (char*)malloc(sizeof(char) * strSize);
        	snprintf(str, strSize, "%s%s", folder, file);
        	if(access(str, F_OK) == -1 ) {
        		printf("Error file %s/%s not found. The %s file should be your main patch.\n", folder, file, file);
        		return false;
        	}
        	free(str);
        
        	// analog setup
        	gAnalogChannelsInUse = context->analogInChannels;
        	gDigitalChannelsInUse = context->digitalChannels;
        	printf("Audio channels in use: %d\n", context->audioOutChannels);
        	printf("Analog channels in use: %d\n", gAnalogChannelsInUse);
        	printf("Digital channels in use: %d\n", gDigitalChannelsInUse);
        
        	// Channel distribution
        	gFirstAnalogInChannel = std::max(context->audioInChannels, context->audioOutChannels);
        	gFirstAnalogOutChannel = gFirstAnalogInChannel;
        	gFirstDigitalChannel = gFirstAnalogInChannel + std::max(context->analogInChannels, context->analogOutChannels);
        	if(gFirstDigitalChannel < minFirstDigitalChannel)
        		gFirstDigitalChannel = minFirstDigitalChannel; //for backwards compatibility
        	gLibpdDigitalChannelOffset = gFirstDigitalChannel + 1;
        	gFirstScopeChannel = gFirstDigitalChannel + gDigitalChannelsInUse;
        
        	gChannelsInUse = gFirstScopeChannel + gScopeChannelsInUse;
        
        	// Create receiverNames for digital channels
        	generateDigitalNames(gDigitalChannelsInUse, gLibpdDigitalChannelOffset, gReceiverInputNames, gReceiverOutputNames);
        
        	// digital setup
        	if(gDigitalEnabled)
        	{
        		dcm.setCallback(sendDigitalMessage);
        		if(gDigitalChannelsInUse > 0){
        			for(unsigned int ch = 0; ch < gDigitalChannelsInUse; ++ch){
        				dcm.setCallbackArgument(ch, (void*) gReceiverInputNames[ch].c_str());
        			}
        		}
        	}
        
        	unsigned int n = 0;
        	while(n < gMidiPortNames.size())
        	{
        		Midi* newMidi = openMidiDevice(gMidiPortNames[n], false, false);
        		if(newMidi)
        		{
        			midi.push_back(newMidi);
        			++n;
        		} else {
        			gMidiPortNames.erase(gMidiPortNames.begin() + n);
        		}
        	}
        	dumpMidi();
        
        	// check that we are not running with a blocksize smaller than gLibPdBlockSize
        	gLibpdBlockSize = libpd_blocksize();
        	if(context->audioFrames < gLibpdBlockSize){
        		fprintf(stderr, "Error: minimum block size must be %d\n", gLibpdBlockSize);
        		return false;
        	}
        
        	// set hooks before calling libpd_init
        	libpd_set_printhook(Bela_printHook);
        	libpd_set_floathook(Bela_floatHook);
        	libpd_set_messagehook(Bela_messageHook);
        	libpd_set_noteonhook(Bela_MidiOutNoteOn);
        	libpd_set_controlchangehook(Bela_MidiOutControlChange);
        	libpd_set_programchangehook(Bela_MidiOutProgramChange);
        	libpd_set_pitchbendhook(Bela_MidiOutPitchBend);
        	libpd_set_aftertouchhook(Bela_MidiOutAftertouch);
        	libpd_set_polyaftertouchhook(Bela_MidiOutPolyAftertouch);
        	libpd_set_midibytehook(Bela_MidiOutByte);
        
        	//initialize libpd. This clears the search path
        	libpd_init();
        	//Add the current folder to the search path for externals
        	libpd_add_to_search_path(".");
        	libpd_add_to_search_path("../pd-externals");
        
        	libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate);
        	gInBuf = get_sys_soundin();
        	gOutBuf = get_sys_soundout();
        
        	// start DSP:
        	// [; pd dsp 1(
        	libpd_start_message(1);
        	libpd_add_float(1.0f);
        	libpd_finish_message("pd", "dsp");
        
        	// Bind your receivers here
        	for(unsigned int i = 0; i < gDigitalChannelsInUse; i++)
        		libpd_bind(gReceiverOutputNames[i].c_str());
        	libpd_bind("bela_setDigital");
        	libpd_bind("bela_setMidi");
        
        	// open patch:
        	gPatch = libpd_openfile(file, folder);
        	if(gPatch == NULL){
        		printf("Error: file %s/%s is corrupted.\n", folder, file);
        		return false;
        	}
        
        	// If the user wants to use the multiplexer capelet,
        	// the patch will have to contain an array called "bela_multiplexer"
        	// and a receiver [r bela_multiplexerChannels]
        	if(context->multiplexerChannels > 0 && libpd_arraysize(multiplexerArray) >= 0){
        		pdMultiplexerActive = true;
        		multiplexerArraySize = context->multiplexerChannels * context->analogInChannels;
        		// [; bela_multiplexer ` multiplexerArraySize` resize(
        		libpd_start_message(1);
        		libpd_add_float(multiplexerArraySize);
        		libpd_finish_message(multiplexerArray, "resize");
        		// [; bela_multiplexerChannels `context->multiplexerChannels`(
        		libpd_float("bela_multiplexerChannels", context->multiplexerChannels);
        	}
        
        	// Tell Pd that we will manage the io loop,
        	// and we do so in an Auxiliary Task
        #ifdef PD_THREADED_IO
        	sys_dontmanageio(1);
        	AuxiliaryTask fdTask;
        	fdTask = Bela_createAuxiliaryTask(fdLoop, 50, "libpd-fdTask", NULL);
        	Bela_scheduleAuxiliaryTask(fdTask);
        #endif /* PD_THREADED_IO */
        
        	dcm.setVerbose(false);
        // MODIFICATION START
        	//touchSensor.setup(1, 0x18, Trill::DIFF,20,2);
        	touchSensorMain.setup(1, 0x18, Trill::DIFF,2,2);
        	Bela_scheduleAuxiliaryTask(Bela_createAuxiliaryTask(readCapSensorLoop, 50, "touchSensorRead", NULL));
        // MODIFICATION END
        	return true;
        }
        
        void render(BelaContext *context, void *userData)
        {
        // MODIFICATION START
        /*
        	libpd_start_message(touchSensor.numSensors());
        	for(unsigned int n = 0; n < touchSensor.numSensors(); ++n)
        	{
        		libpd_add_float(touchSensor.rawData[n]/(2048.f));
        		// libpd_add_float(touchSensor.rawData[n]);
        	}
        	libpd_finish_message("bela_Trill", "list");
        	*/
        	//main_sensor
        	libpd_start_message(touchSensorMain.numSensors());
        	for(unsigned int n = 0; n < touchSensorMain.numSensors(); ++n)
        	{
        		libpd_add_float(touchSensorMain.rawData[n]/(2048.f));
        		// libpd_add_float(touchSensor.rawData[n]);
        	}
        	libpd_finish_message("bela_Trill_main", "list");
        // MODIFICATION END
        	int num;
        #ifdef PARSE_MIDI
        	for(unsigned int port = 0; port < midi.size(); ++port){
        		while((num = midi[port]->getParser()->numAvailableMessages()) > 0){
        			static MidiChannelMessage message;
        			message = midi[port]->getParser()->getNextChannelMessage();
        			rt_printf("On port %d (%s): ", port, gMidiPortNames[port].c_str());
        			message.prettyPrint(); // use this to print beautified message (channel, data bytes)
        			switch(message.getType()){
        				case kmmNoteOn:
        				{
        					int noteNumber = message.getDataByte(0);
        					int velocity = message.getDataByte(1);
        					int channel = message.getChannel();
        					libpd_noteon(channel + port * 16, noteNumber, velocity);
        					break;
        				}
        				case kmmNoteOff:
        				{
        					/* PureData does not seem to handle noteoff messages as per the MIDI specs,
        					 * so that the noteoff velocity is ignored. Here we convert them to noteon
        					 * with a velocity of 0.
        					 */
        					int noteNumber = message.getDataByte(0);
        	//				int velocity = message.getDataByte(1); // would be ignored by Pd
        					int channel = message.getChannel();
        					libpd_noteon(channel + port * 16, noteNumber, 0);
        					break;
        				}
        				case kmmControlChange:
        				{
        					int channel = message.getChannel();
        					int controller = message.getDataByte(0);
        					int value = message.getDataByte(1);
        					libpd_controlchange(channel + port * 16, controller, value);
        					break;
        				}
        				case kmmProgramChange:
        				{
        					int channel = message.getChannel();
        					int program = message.getDataByte(0);
        					libpd_programchange(channel + port * 16, program);
        					break;
        				}
        				case kmmPolyphonicKeyPressure:
        				{
        					int channel = message.getChannel();
        					int pitch = message.getDataByte(0);
        					int value = message.getDataByte(1);
        					libpd_polyaftertouch(channel + port * 16, pitch, value);
        					break;
        				}
        				case kmmChannelPressure:
        				{
        					int channel = message.getChannel();
        					int value = message.getDataByte(0);
        					libpd_aftertouch(channel + port * 16, value);
        					break;
        				}
        				case kmmPitchBend:
        				{
        					int channel = message.getChannel();
        					int value =  ((message.getDataByte(1) < 7)| message.getDataByte(0)) - 8192;
        					libpd_pitchbend(channel + port * 16, value);
        					break;
        				}
        				case kmmSystem:
        				// currently Bela only handles sysrealtime, and it does so pretending it is a channel message with no data bytes, so we have to re-assemble the status byte
        				{
        					int channel = message.getChannel();
        					int status = message.getStatusByte();
        					int byte = channel | status;
        					libpd_sysrealtime(port, byte);
        					break;
        				}
        				case kmmNone:
        				case kmmAny:
        					break;
        			}
        		}
        	}
        #else
        	int input;
        	for(unsigned int port = 0; port < NUM_MIDI_PORTS; ++port){
        		while((input = midi[port].getInput()) >= 0){
        			libpd_midibyte(port, input);
        		}
        	}
        #endif /* PARSE_MIDI */
        	unsigned int numberOfPdBlocksToProcess = context->audioFrames / gLibpdBlockSize;
        
        	// Remember: we have non-interleaved buffers and the same sampling rate for
        	// analogs, audio and digitals
        	for(unsigned int tick = 0; tick < numberOfPdBlocksToProcess; ++tick)
        	{
        		//audio input
        		for(int n = 0; n < context->audioInChannels; ++n)
        		{
        			memcpy(
        				gInBuf + n * gLibpdBlockSize,
        				context->audioIn + tick * gLibpdBlockSize + n * context->audioFrames,
        				sizeof(context->audioIn[0]) * gLibpdBlockSize
        			);
        		}
        
        		// analog input
        		for(int n = 0; n < context->analogInChannels; ++n)
        		{
        			memcpy(
        				gInBuf + gLibpdBlockSize * gFirstAnalogInChannel + n * gLibpdBlockSize,
        				context->analogIn + tick * gLibpdBlockSize + n * context->analogFrames,
        				sizeof(context->analogIn[0]) * gLibpdBlockSize
        			);
        		}
        		// multiplexed analog input
        		if(pdMultiplexerActive)
        		{
        			// we do not disable regular analog inputs if muxer is active, because user may have bridged them on the board and
        			// they may be using half of them at a high sampling-rate
        			static int lastMuxerUpdate = 0;
        			if(++lastMuxerUpdate == multiplexerArraySize){
        				lastMuxerUpdate = 0;
        				libpd_write_array(multiplexerArray, 0, (float *const)context->multiplexerAnalogIn, multiplexerArraySize);
        			}
        		}
        
        		unsigned int digitalFrameBase = gLibpdBlockSize * tick;
        		unsigned int j;
        		unsigned int k;
        		float* p0;
        		float* p1;
        		// digital input
        		if(gDigitalEnabled)
        		{
        			// digital in at message-rate
        			dcm.processInput(&context->digital[digitalFrameBase], gLibpdBlockSize);
        
        			// digital in at signal-rate
        			for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
        				unsigned int digitalFrame = digitalFrameBase + j;
        				for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstDigitalChannel;
        						k < 16; ++k, p1 += gLibpdBlockSize) {
        					if(dcm.isSignalRate(k) && dcm.isInput(k)){ // only process input channels that are handled at signal rate
        						*p1 = digitalRead(context, digitalFrame, k);
        					}
        				}
        			}
        		}
        
        		libpd_process_sys(); // process the block
        
        		// digital outputs
        		if(gDigitalEnabled)
        		{
        			// digital out at signal-rate
        			for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
        				unsigned int digitalFrame = (digitalFrameBase + j);
        				for (k = 0, p1 = p0  + gLibpdBlockSize * gFirstDigitalChannel;
        					k < context->digitalChannels; k++, p1 += gLibpdBlockSize)
        				{
        					if(dcm.isSignalRate(k) && dcm.isOutput(k)){ // only process output channels that are handled at signal rate
        						digitalWriteOnce(context, digitalFrame, k, *p1 > 0.5);
        					}
        				}
        			}
        
        			// digital out at message-rate
        			dcm.processOutput(&context->digital[digitalFrameBase], gLibpdBlockSize);
        		}
        
        		// scope output
        		for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
        			for (k = 0, p1 = p0 + gLibpdBlockSize * gFirstScopeChannel; k < gScopeChannelsInUse; k++, p1 += gLibpdBlockSize) {
        				gScopeOut[k] = *p1;
        			}
        			scope.log(gScopeOut[0], gScopeOut[1], gScopeOut[2], gScopeOut[3]);
        		}
        
        		// audio output
        		for(int n = 0; n < context->audioOutChannels; ++n)
        		{
        			memcpy(
        				context->audioOut + tick * gLibpdBlockSize + n * context->audioFrames,
        				gOutBuf + n * gLibpdBlockSize,
        				sizeof(context->audioOut[0]) * gLibpdBlockSize
        			);
        		}
        
        		//analog output
        		for(int n = 0; n < context->analogOutChannels; ++n)
        		{
        			memcpy(
        				context->analogOut + tick * gLibpdBlockSize + n * context->analogFrames,
        				gOutBuf + gLibpdBlockSize * gFirstAnalogOutChannel + n * gLibpdBlockSize,
        				sizeof(context->analogOut[0]) * gLibpdBlockSize
        			);
        		}
        	}
        }
        
        void cleanup(BelaContext *context, void *userData)
        {
        	for(auto a : midi)
        	{
        		delete a;
        	}
        	libpd_closefile(gPatch);
        	delete [] gScopeOut;
        }

        Ok, can you also tell me what is the output of grep v0 /etc/motd, and how you updated your code last?

          giuliomoro the output from grep v0 /etc/motd is Bela image, v0.3.7a, 16 October 2019. i did not update this code myself, so i can't answer this immediately.. @Fedde could you specify this further?

          ok if it's the latest image, then I don't need further detail. Can you confirm if you have a _main.pd file in the project folder?

            giuliomoro yes i do have a _main.pd file in the project folder. (does it matter that it has a subpatch inside?)

              yannick a _main.pd file in the project folder. (does it matter that it has a subpatch inside?)

              it doesn't matter that it has a subpatch inside, as long as it is located in the project folder and not in a subdirectory of the project folder.

              The above file compiles and runs fine for me. Try one of the following:

              • If you are building with the IDE, go to the Settings tab and add to the Make Parameters: box the following: AT=.
              • If you are building using the scripts/build_project.sh script from the host, add -m "AT=" at the end of the command line
              • if you are building directly with make on the board, simply append AT= to the make line

              The three actions above will give a more verbose output, please run one of them and paste the output here.