Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only every other line of config file is parsed #4

Open
v1s1n opened this issue Mar 3, 2022 · 8 comments
Open

only every other line of config file is parsed #4

v1s1n opened this issue Mar 3, 2022 · 8 comments

Comments

@v1s1n
Copy link

v1s1n commented Mar 3, 2022

At the moment, remapping CC 0 to any other CC will instead output CC 0. Tested on version 1.3.0 using jack 1.9.17, bridging with a2j.

@v1s1n
Copy link
Author

v1s1n commented Mar 3, 2022

Edit: Midi remapping CC0 does work, but only seems to begin on line 3. For example:

midi2midi-config-1.3
9-16
0>0
1>11

will remap 1>11, but

midi2midi-config-1.3
9-16
1>11

will not remap CC1

@v1s1n
Copy link
Author

v1s1n commented Mar 3, 2022

debug:

DEBUG: Reading file '9-16.m2m' (in midi2midi.c on line 210)
DEBUG: Read port name '9-16' (in midi2midi.c on line 286)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 3 '1>11' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 4 '3>13' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 5 '5>15' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 6 '7>17' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 7 '9>19' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)
DEBUG: Reached end of file '9-16.m2m' (in midi2midi.c on line 489)

config:

midi2midi-config-1.3
9-16
0>10
1>11
2>12
3>13
4>14
5>15
6>16
7>17
8>18
9>19

seems like it's only reading every other line?

@v1s1n v1s1n changed the title midi remapping for 0>n outputs 0 only every other line of config file is parsed Mar 3, 2022
@aiobofh
Copy link
Owner

aiobofh commented Mar 3, 2022

@v1s1n hi there! Hm... There might be an issue with linefeeds or something like that in your config. The code is quite (very) stupid when parsing. It uses fscanf which is not recommended, nor good :) And it expects lines to end with \n and only \n. Is your config file MS-DOS/Windows encoded?

@v1s1n
Copy link
Author

v1s1n commented Mar 3, 2022

No, they are encoded in plain ascii.

$ file 9-16.m2m -i
9-16.m2m: text/plain; charset=us-ascii

I did a little more testing. When the lines between are blank, it treats them as whitespace as expected. However, when I put note:note mappings in those spaces (1:1, 2:2, etc.) then they are not parsed, but all of my CC mappings are.

DEBUG: Reading file '9-16.m2m' (in midi2midi.c on line 210)
DEBUG: Read port name '9-16' (in midi2midi.c on line 286)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 3 '0>10' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 4 '1>11' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)

and so on. my config file is:

midi2midi-config-1.3
9-16
0:0
0>10
1:1
1>11
2:2
2>12
3:3

when i remove line 3 (0:0) then only the note mappings are parsed, again following every other line. Interestingly, though, my very last line (9>19) is parsed

DEBUG: Reading file '9-16.m2m' (in midi2midi.c on line 210)
DEBUG: Read port name '9-16' (in midi2midi.c on line 286)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 3 '1:1' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 345)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 4 '2:2' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 345)

et cetera:

DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 345)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 11 '9:9' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 345)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 311)
DEBUG: Reading line 12 '9>19' (in midi2midi.c on line 323)
DEBUG: Identified line as TT_CC_TO_CC (>) (in midi2midi.c on line 339)
DEBUG: Reached end of file '9-16.m2m' (in midi2midi.c on line 489)

I'll do more testing, but it definitely seems like only the even-numbered mapping lines are being parsed, apart from the last one.

@Java-Jim
Copy link

Java-Jim commented Oct 23, 2023

I had problems that no from or to Notes nor the commandtype c gets recognized from the config file, so i checked the code.

First of all the line_number 2 of the config file holds the port name. So you have to fill a name in the second line, which is send to jack for identification.

In my case the the errors begun with the first line, which happened also with the shipped m2m config files.
I changed the midi2midi.c code for version checking as following and the notes get recognized.

char line [50];

if (1 == line_number) {
      /*
       * Make sure that we can handle the file version :)
       */
		fgets(line, 50, fd); 
		line[strlen(line)-1] = 0;
		if (strcmp(line, "midi2midi-config-1.3") == 0) {debug("The file '%s' is a 1.3 file", filename);}
		else if (strcmp(line, "midi2midi-config-1.2") == 0) {debug("The file '%s' is a 1.2 file", filename);}
		else if (strcmp(line, "midi2midi-config-1.1") == 0) {debug("The file '%s' is a 1.1 file", filename);}
		else if (strcmp(line, "midi2midi-config-1.0") == 0) {debug("The file '%s' is a 1.0 file", filename);}
		else  {error("The file '%s' is not a midi2midi configuration file.", filename);}      
    continue;
    }

But then i saw the same problem, that every second line gets skipped. That's because of the checking for the channel parameter. When there is no fourth parameter channel given, the fscanf line is called a second time resulting in skipping of the first reading!
So i set the reading position back, before reading again with three parameters. And it works!
check the code starting at line 304

      int use_channel = 0;
      translation_type type = TT_NONE;
      /*
       * Read each line of the configuration file and insert translations into
       * the table.
       */
      fpos_t pos;
      fgetpos(fd, &pos);
      if (4 != fscanf(fd, "%3d%1c%3d,%3d\n", &from, &c, &to, &channel)) {
			debug("Falling back to only %d:1 channel", 1);
		  	fsetpos(fd,&pos);
       		        fscanf(fd, "%3d%1c%3d\n", &from, &c, &to);
	  		//debug("Line %d '%d%c%d'", line_number, from, c, to);  
      }
DEBUG: Reading file '/etc/midi-utils/toontrack.m2m' (in midi2midi.c on line 210)
DEBUG: The file '/etc/midi-utils/toontrack.m2m' is a 1.1 file (in midi2midi.c on line 235)
DEBUG: Read port name 'Toontrack-HelixDeathMetal' (in midi2midi.c on line 255)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 282)
DEBUG: Reading line 3 '17:53' (in midi2midi.c on line 296)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 318)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 282)
DEBUG: Reading line 4 '36:37' (in midi2midi.c on line 296)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 318)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 282)
DEBUG: Reading line 5 '38:40' (in midi2midi.c on line 296)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 318)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 282)
DEBUG: Reading line 6 '49:61' (in midi2midi.c on line 296)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 318)
DEBUG: Falling back to only 1:1 channel (in midi2midi.c on line 282)
DEBUG: Reading line 7 '57:62' (in midi2midi.c on line 296)
DEBUG: Identified line as TT_NOTE_TO_NOTE (:) (in midi2midi.c on line 318)
DEBUG: Reached end of file '/etc/midi-utils/toontrack.m2m' (in midi2midi.c on line 462)
``

@aiobofh
Copy link
Owner

aiobofh commented Oct 23, 2023

@Java-Jim Wow :) People are using this!? Great, i guess - but it's kind of hacky. But minimalistic. Nice investigative work! :) My bad. Great job. I'll try to introduce some kind of patch based on your work. You're not stranded now? This probably explains the issues @v1s1n have too.

@Java-Jim
Copy link

I cloned your repo yesterday, as i am trying to use my library_of_the_extreme MIDI files from the SuperiorDrummer together with Ardour and Helix. The notes were wrong and a came along your Software searching around. Exactly what i need for this, so i hacked it to work. That's the great thing about opensource. Had not already tested that it sounds like it should, but i can see that the in/out ports appeared in Jack. Will test it this evening. Thank you!

@aiobofh
Copy link
Owner

aiobofh commented Oct 23, 2023

@Java-Jim haha, I see my good old friend @ascallonisi have a branch that fixes this shit a bit nicer, have a looksie on the ale_note2cc_dev branch. Way more elegantish error handling there, it seems. FOUR YEARS AGO :D Hehe sigh. This is mainly a hack we've been using in our studios for tinkering and for a RaspberryPi USB<->MIDI thing for forest improvisations... I think I made it originally to play SID drums with my Roland TD-9 :D, and translate an Event EzBus transport (CC) to Jack-Transport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants