detecting wake up from sleep

May 7, 2011 at 12:21pm

detecting wake up from sleep

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.

#56509
May 7, 2011 at 1:18pm

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:

http://cycling74.com/category/did-you-know/

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

Benny

#202583
May 7, 2011 at 2:47pm

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

#202584
May 8, 2011 at 2:55pm

Is there no way Max can detect sleep mode?

#202585
May 11, 2011 at 9:32am

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.

#202586
May 14, 2011 at 1:51pm

thank very much peter, wasn’t aware of the date object. should work fine

#202587
May 14, 2011 at 5:22pm

@bin
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,

Attachments:
  1. consciousness.zip
#202588
May 16, 2011 at 10:05pm

@jan.jdo

brilliant! nice coding. thanks

#202589

You must be logged in to reply to this topic.