Diff for .maxpat?

    Mar 31 2011 | 9:35 pm
    Has anyone ever built a diff specifically for .maxpat files?
    Yes, I know you can use any standard diff for text files on the Max JSON format, but the problem is that very minor changes in the Max patch can result in a re-ordering of the objects in the .maxpat that will completely confuse a conventional diff. I have in front of me a large patch where I've made very few changes, but a text diff lists 9 pages of modifications.
    What's needed is something that can parse enough of the JSON format to recognize it as a list of "objects" with id numbers and then compare the properties of identical ids, regardless of the order they occur in either file.
    Ideally it would be able to differentiate between deletions/insertions ("major" changes) and things like moving an object (more minor, but of course with the potential for effecting left-to-right operation) and cosmetic issues (color). And so on.
    Anyone old enough to remember "resource forks" and ResDiff will recognize what I'm looking for.
    Sometimes minor changes to a patch can have catastrophic effects on how it works, and a tool like this would help in tracking down this kind of problem.
    Any takers?

    • Mar 31 2011 | 9:41 pm
      convert to max4, save as .txt, ... ? :D :D sorry.
    • Mar 31 2011 | 11:25 pm
      ;max sortpatcherdictonsave 1
      is probably going to be your friend.
    • Apr 01 2011 | 9:50 am
      Thanks, Andrew! sortpatcherdictonsave reduces the diff list by almost 80%. This is a big help.
      There are still lots of spurious "differences" that aren't really differences, though. The order of boxes, for instance, is still arbitrary. So in one version you might have a comment box with id obj-71 at the beginning of the file, and in the next version the same object can be at the end. And because diff works on a line-by-line basis it ends up matching lines with braces while flagging differences on lines with text. All of this makes it harder to work out where there's a real change to the patch.
      Seems sortpatcherdictonsave is the best we've got and it will be my pal. A more capable "MaxpatDiff", if there ever is one, would be my soulmate.
      And anyone willing to take on programming a good diff for .maxpat-files will be a Max superhero!
    • Dec 09 2013 | 11:13 pm
      I do have some experience in developing semantic comparison tools, so I might have what it takes to become a Max superhero. :)
      Semantic comparison tools parse and interpret the contents of the files, as opposed to treating them as plain text. This enables the tool to detect the actual changes in meaning as opposed to changes in content. The basic version would list these changes in a meaningful, human-readable way, which is already useful by itself. However, there is no reason to stop there. Since the patches contain the graphical coordinates as well, the changes could be displayed and highlighted on a diagram as well. Again, I have done this before, so something like this would be right up my alley.
      The big question is what programming language and runtime environment to use. Most of my experience is in Java, so that would probably be the easiest. However, I would happily use this as a learning opportunity to pick up a new language and/or application framework. It should preferably:
      • work on Windows and Mac OS X
      • have no third-party dependencies that the user needs to install separately
      Any thought, ideas, suggestions?
    • Dec 10 2013 | 11:09 pm
      Java probably has a lot going for it.
      JavaScript would have the possible advantage of being able to parse JSON with eval(). Although JavaScript is prototype-based, rather than class-based the way Java is, you can emulate a class hierarchy by using prototypes.
      It's hard to say, offhand, which is the "better" choice, or how much a hierarchical class structure will help you. The tool you're most familiar with might be the one to go with.
      Also note that, although JavaScript looks a lot like Java, there are some significant differences that will thoroughly trip up the unwary. If you decide to try JScript, spend some quality time with the language spec.
      PS: It would be very cool if this works out!