3 Replies Latest reply on May 27, 2008 12:10 PM by Production Monkey

    Tempo not exactly

    Level 7
      Hello:
      I'm using xMidi Xtras to make a metronome but the tempo is not accurate.
      Sometimes is quicker other not. I don't know if is a programation problem
      or the problem is in the Xtra.
      First I instantiate the XtraMidi, so on StepFrame I sound the pitch.
      Can you hlep me please?
      Thank you very much.



      global gTimer
      global gEmpieza
      on mouseUp me
      gTimer=new(script "TimerObject",15)
      gEmpieza=True
      end
      --------------------
      -- Welcome to Director --
      property pStartTicks, pWaitTicks
      global gTimer
      global gEmpieza
      global xm

      on new me, Howmuch

      set pStartTicks = the ticks
      set pWaitTicks = Howmuch
      add the actorList, me
      return me

      end

      on stepFrame me
      if gEmpieza then
      if the ticks > pStartTicks + pWaitTicks then
      sendNoteOn(xm, 10, 64, 60)
      set pStartTicks = the ticks --begins again
      end if
      end if
      end


      on killTimer me
      deleteOne the actorList, me
      set gTimer = 0
      end



        • 1. Re: Tempo not exactly
          Production Monkey Level 3
          A timeout object will likely be more accurate and certainly will provide more precision and simplify the code. Below is some code to get you started. I changed some names to better reflect their purpose and to indicate their globalness. I also deleted "gEmpieza". The variable appears to be a flag to turn the metronome on or off. Using an external global to do that is a bad idea. I added a "pause/start" interface, which is the proper way to handle that. I don't have a copy of the midi xtra so this code is untested.


          global gMetronome


          on mouseUp me
          if gMetronome.objectP = false then -- stop multiple instantiations
          gMetronome = script ("Metronome").new(250) -- quarter of a second in milliseconds
          end if
          end

          --------------------

          -- Metronome Parent script

          global gXM -- Midi xtra
          global gMetronome

          property pPeriod -- time in milliseconds between each update
          property pTimeOb -- timeout object



          on new me, PeriodTime
          pPeriod = PeriodTime
          pTimeOb = timeout().new("MetronomeTimer_" & me, pPeriod, #SendNote, me)
          return me
          end new

          on SendNote me, TimeOb
          gXM.sendNoteOn(10, 64, 60)
          end SendNote


          on pause me
          pTimeOb.period = 0
          end


          on start me
          pTimeOb.period = pPeriod
          end


          on setPeriod me, NewPeriod -- milliseconds
          pPeriod = NewPeriod
          pTimeOb.period = pPeriod
          end setPeriod


          on killMetronome me
          if pTimeOb.objectP then
          pTimeOb.forget()
          pTimeOb = 0
          end if
          gMetronome = void
          end killTimer
          • 2. Re: Tempo not exactly
            Level 7
            Thank you very much.
            I'm trying your code but an error happens:
            in this line pTimeOb = timeout().new("MetronomeTimer_" & me,
            pPeriod, #SendNote, me)

            One parameter expected.

            Here is a copy of MIDI Xtras
            http://www.troikatronix.com/files/xmidi_win_demo.zip
            http://www.troikatronix.com/files/XMidi_Documentation.pdf


            • 3. Tempo not exactly
              Production Monkey Level 3
              If your version of Director is lower than 10.0, then the timeout syntax is different.

              pTimeOb = timeout("MetronomeTimer_" & me).new(pPeriod, #SendNote, me)