Coder Social home page Coder Social logo

Comments (4)

SpotlightKid avatar SpotlightKid commented on May 23, 2024

Towards your first question, the general strategy would be:

  • get the sample rate
  • calculate your delay length in terms of samples and numbers of buffer periods
  • read the midi events and store them together with a timestamp (e.g. samples since startup)
  • in each period, check if the delay number of buffer periods and samples has passed, comparing the stored timestamps to the current number of periods/samples since startup, and, if yes
  • add the stored midi events to the output buffer

from protoplug.

coderofsalvation avatar coderofsalvation commented on May 23, 2024

I think I already got the midimsg delay working (I looked at the midiChordify example):

require "include/protoplug"

local mididelay
local delayBuf = {}
local playing = false

function plugin.processBlock(samples, smax, midiBuf)
  blockEvents = {}
  -- analyse midi buffer and push them to midiDelaybuffer
  for ev in midiBuf:eachEvent() do
    ev.time = ev.time + mididelay
    table.insert( delayBuf, ev )    
  end
  -- fill midi buffer with delayed notes (if any)
  midiBuf:clear()
  sendDelayBuf(midiBuf)
  sendMMC()
end

function sendDelayBuf(midiBuf)
  if #delayBuf>0 then
    for _,e in ipairs(delayBuf) do
      if e.time < smax then       
        midiBuf:addEvent(e)
        table.remove( delayBuf, _ )
        print "midi msg!"
      else
        e.time = e.time - smax
      end
    end
  end
end

function sendMMC()
  if not playing and plugin.PositionInfo.isPlaying
    -- send start to midi out ( 0xF0 0x7F 0x7F 0x06 0x02 )
  end
  if playing and not plugin.PositionInfo.isPlaying
    -- send stop to midi out ( 0xF0 0x7F 0x7F 0x06 0x01 )
  end   
end 

params = plugin.manageParams {
  {
    name = "Mididelay";
    type = "int";
    max = 50000;
    changed = function(val) mididelay = val end;
  }
}

Now I only need to send out the midi bytes by creating some custom midi events.
WDYT?

ps. actually its not important to deal with real milliseconds since the only purpose of the slider is to do a manual correction by ear. (compensate hardware/software midi delay)

from protoplug.

pac-dev avatar pac-dev commented on May 23, 2024

For receiving start and stop events from the host, you can use plugin.getCurrentPosition().isPlaying. Here's an example:

require "include/protoplug"

local oldPlaying = false

function plugin.processBlock(samples, smax, midiBuf)
    local info = plugin.getCurrentPosition()
    if info and info.isPlaying ~= oldPlaying then
        print (info.isPlaying and "Host started playing!" or "Host stopped!")
        oldPlaying = info.isPlaying
    end
end

For sending custom MIDI messages, the API docs are pretty explicit, there's even an example!:

http://www.osar.fr/protoplug/api/modules/midi.html#midi.Event:Event

from protoplug.

coderofsalvation avatar coderofsalvation commented on May 23, 2024

indeed nothing wrong with those docs!
thnx

from protoplug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.