;Bpm Bridge
;developed by Triceratupuz Lab
;http://triceratupuz.altervista.org/
;REV 20161229
;
TO RECEIVE OSC USE THIS INSTRUMENT:
instr X
kf1 init 0
nxtmsg:
kk OSClisten gihandle, "/BPM", "f", kf1
if (kk == 0) goto ex
;printk 0,kf1
kgoto nxtmsg
ex:
endin
form size(155, 267), caption("Bpm Bridge"), pluginID("vpat"), colour(240,240,240), guirefresh(1)
label bounds(2, 0, 49, 13), text("BPM"), align("centre")
numberbox bounds(2, 22, 50, 20), channel("Bpm_num"), colour("white"), fontcolour("black"), range(1, 500, 60, 1, 0.01)
rslider bounds(62, 0, 80, 60), channel("Bpm_rot"), range(1, 500, 60, 1, 0.01); text("BpM")
numberbox bounds(2, 61, 49, 20), channel("Bpm_host_val"), colour("white"), fontcolour("black"), range(0, 500, 1, 1, 0.01)
button bounds(52, 61, 100, 20), channel("Bpm_host"), text("Get Host","<-Host"), colour:0("black"),colour:1("red")
button bounds(52, 83, 100, 20), channel("Bpm_tap"), text("TapTempo"), colour:0("gray"),colour:1("gray"), latched(1)
label bounds(2, 104, 49, 13), text("MIDI"), align("right")
combobox bounds(52, 104, 100, 20), channel("midi_C"), value(1), items("NO Midi", "PC", "CC", "NOTEON")
label bounds(2, 124, 49, 13), text("channel"), align("right")
combobox bounds(52, 124, 100, 20), channel("midi_CH"), value(1), items("CH1", "CH2", "CH3", "CH4", "CH5", "CH6", "CH7", "CH8", "CH9", "CH10", "CH11", "CH12", "CH13", "CH14", "CH15", "CH16", "CH_OMNI")
label bounds(2, 144, 49, 13), text("Number"), align("right")
numberbox bounds(52, 144, 100, 20), channel("midi_V1"), colour("white"), fontcolour("black"), range(0, 127, 1, 1, 1)
label bounds(2, 164, 49, 13), text("Value"), align("right")
numberbox bounds(52, 164, 100, 20), channel("midi_V2"), colour("white"), fontcolour("black"), range(0, 127, 1, 1, 1)
label bounds(2, 185, 150, 13), text("OSC Output"), align("centre")
label bounds(2, 205, 49, 13), text("address"), align("right")
texteditor bounds(52, 205, 100, 19), channel("address"), text("localhost")
label bounds(2, 225, 49, 13), text("port"), align("right")
texteditor bounds(52, 225, 100, 19), channel("port"), text("5775")
label bounds(2, 245, 49, 13), text("dest"), align("right")
texteditor bounds(52, 245, 100, 19), channel("dest"), text("/BPM")
-n -d
sr = 44100
ksmps = 64
nchnls = 2
0dbfs=1
massign 0, 0
gkBpM init 60
gkLastTap init 0
instr 1
;rotary
kBPM_r chnget "Bpm_rot"
if changed(kBPM_r) == 1 then
chnset kBPM_r, "Bpm_num"
gkBpM = kBPM_r
endif
;textbox
kBPM_n chnget "Bpm_num"
if changed(kBPM_n) == 1 then
chnset kBPM_n, "Bpm_rot"
gkBpM = kBPM_n
endif
;taptempo
kBPM_t chnget "Bpm_tap"
if changed(kBPM_t) == 1 then
event "i", 5, 0, -1
endif
;midi tap
kmidi_c chnget "midi_C"
if kmidi_c > 1 then
kstatusOK = 0
kchanOK = 0
kdata1OK = 0
kdata2OK = 0
kstatus, kchan, kdata1, kdata2 midiin
if kstatus == 192 && kmidi_c == 2 then
kstatusOK = 1
kdata2OK = 1
endif
if kstatus == 176 && kmidi_c == 3 then
kstatusOK = 1
endif
if kstatus == 144 && kmidi_c == 4 then
kstatusOK = 1
kdata2OK = 1
endif
kmidi_ch chnget "midi_CH"
if (kmidi_ch == 17) || (kmidi_ch == kchan) then
kchanOK = 1
endif
kmidi_v1 chnget"midi_V1"
if (kmidi_v1 == kdata1) then
kdata1OK = 1
endif
kmidi_v2 chnget"midi_V2"
if (kmidi_v2 == kdata2) then
kdata2OK = 1
endif
if (kstatusOK == 1) && (kchanOK == 1) && (kdata1OK == 1) && (kdata2OK == 1) then
event "i", 5, 0, -1
endif
endif
endin
instr 5;tap tempo calculator
ktime times
if (ktime - gkLastTap) < 3 then
kbpm = 60 / (ktime - gkLastTap)
chnset kbpm, "Bpm_rot"
chnset kbpm, "Bpm_num"
gkLastTap = ktime
gkBpM = kbpm
else
gkLastTap = ktime
endif
turnoff
endin
instr 9;trigger OSC send
;host
kBPM_h chnget "Bpm_host"
kBPM_hv chnget "HOST_BPM"
chnset kBPM_hv, "Bpm_host_val"
if kBPM_h > 0 then
gkBpM = kBPM_hv
endif
;revert to GUI value
if kBPM_h == 0 && changed(kBPM_h) == 1 then
kBPM_r chnget "Bpm_num"
gkBpM = kBPM_r
endif
;activate trensmission in gkBpM changes
if changed(gkBpM)== 1 then
event "i", 10, 0, -1
endif
endin
instr 10;transmit via OSC
Shost chnget "address"
Sport_ chnget "port"
iport strtol Sport_
Sdest chnget "dest";destination must becgin with /
OSCsend 1, Shost, iport, Sdest, "f" , gkBpM
turnoff
endin
f0 z
i 1 0 -1
i 9 0 -1
e