detecting wake up from sleep

    May 07 2011 | 12:21 pm
    After waking my Imac from sleep, the midiin and midiout objects forget what ports they are assigned to.
    Is there any way of detecting when a computer "wakes up" so I can reassign the midi ports using a bang ? Or some other soultion?
    It gets confusing if i forget to manually reasssign the ports and all my midi ports are messed up.

    • May 07 2011 | 1:18 pm
      You can send each midiin/out a message to tell it which midi port to connect to, so all you need to do is connect a loadmess to each port, containing the appropriate message for the desired connection and trigger them as per the video from week 9 on this page:
      alternatively you could connect a bang to a send object and have multiple receive objects connected to messages to each port. You could hit this once you wake your computer up, setting all your ports back to their desired routings in one fell swoop. Check out the inport.maxhelp tab in the midiin help file for further clarification.
      Hope this helps
    • May 07 2011 | 2:47 pm
      I have already done as you suggest. But I really want to be able to detect when the computer wakes from sleep to automate the process
    • May 08 2011 | 2:55 pm
      Is there no way Max can detect sleep mode?
    • May 11 2011 | 9:32 am
      You could bang a date (say, from something like a [metro 10000] object) and keep tab of the running differences between times. A sleep/wakeup cycle will (almost always) take a good deal longer than 15 seconds, so if the difference between two consecutive outputs from date is longer than that you could re-trigger your assign-MIDI-ports logic.
      There can be a tiny bit of jitter in the metro object, depending on how much other processing is in your patch, so you want to set the test values generously enough that they won't be fooled by any minor deviation coming out of the metro/date combination.
    • May 14 2011 | 1:51 pm
      thank very much peter, wasn't aware of the date object. should work fine
    • May 14 2011 | 5:22 pm
      I see you've solved your problem, but since reading this post I thought about trying to code an external to do the job. Attached is a mac external that detects sleep and wake conditions. I've been to sleep and woken a few times and everything *seems* ok.
      the source is included but may cause some distress?:)
      best regards,
    • May 16 2011 | 10:05 pm
      brilliant! nice coding. thanks