own soundfont for this... Should also work
on iPads (only tested with iPad mini)
Download the linked Dropbox soundfont.
https://www.dropbox.com/s/cp67uvnp4wx5a ... 1.sf2?dl=0
Code: Select all
REM SineTone Generator (100-10k Hz, Midi)
REM sB 5.1 / iPhone 4 / iOS 6.1 / by Operator
REM sine-soundfont -> Audacity & Polyphone
REM V1:
REM Keep note&device volume LOW to avoid
REM harmonics
REM Use slider to decrease button turn
REM increment for "fine" frequency tuning...
REM +pitchbend to next semitone in 31 steps
REM (0-127 -> +/- 2 semitones), so frequency
REM resolution is limited
REM iPad (at least iPad mini 1gen., iOS 9.2.1)
REM run code with device in portrait orientation
REM otherwise, END/DEBUG buttons will not work..
REM see: http://kibernetik.pro/forum/viewtopic.php?f=28&t=1231&p=7333&hilit=Set+Portrait#p7333
'if sine soundfont is not loaded (no Dropbox)
'then instrument #67 (0-127) will run...
NOTES MIDI 0,12,67
'>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<
'load sine soundfont (uncomment next 2 lines)
'NOTES INSTRUMENTS "/midi/Sine_V1.sf2"
'NOTES MIDI 0,12,0 'load instrument(sinetone)
IF DEVICE_TYPE$() = "iPad" THEN
cor_f1 = 1.02 ! cor_f2 = 0.91
ELSE
cor_f1 = 1.0 ! cor_f2 = 1
END IF
SET ORIENTATION PORTRAIT
OPTION SPRITE POS CENTRAL
OPTION ANGLE DEGREES
GRAPHICS
GRAPHICS CLEAR
'helpers
scr.w = SCREEN_WIDTH()
scr.w2 = scr.w/2
scr.h = SCREEN_HEIGHT()
scr.h2 = scr.h/2 + scr.h/40
'----------- Start of Knob Dial -----------'
'knob: circle
FILL COLOR 0.4,0.4,0.4
circ.r = 0.4*scr.w
FILL CIRCLE scr.w2,scr.h2 SIZE circ.r*0.97
'knob: middle cross
'DRAW COLOR 0.7,0.7,0.7
'DRAW SIZE 0.5
'x1 = scr.w2-5 ! y1 = scr.h2
'x2 = scr.w2+5 ! y2 = scr.h2
'DRAW LINE x1,y1 TO x2,y2
'x1 = scr.w2 ! y1 = scr.h2-5
'x2 = scr.w2 ! y2 = scr.h2+5
'DRAW LINE x1,y1 TO x2,y2
'knob: small line
DRAW COLOR 0,0,0
DRAW SIZE 2
x1 = scr.w2 ! y1 = scr.h2 + circ.r*0.65
x2 = scr.w2 ! y2 = scr.h2 + circ.r*0.97
DRAW LINE x1,y1 TO x2,y2
'knob: scan sprite
X = scr.w2 - circ.r*1.1
Y = scr.h2 - circ.r*1.1
W = 2*circ.r*1.1
H = 2*circ.r*1.1
SPRITE "knob" SCAN X,Y, W,H
SPRITE "knob" AT scr.w2, scr.h2
SPRITE "knob" SHOW
'scale: circle
DRAW COLOR 0,0,0
DRAW SIZE 1
DRAW CIRCLE scr.w2,scr.h2 SIZE circ.r
'scale: lines
'log scale 15-345' mapped to 100-10.000Hz
x1 = scr.w2
y1 = scr.h2
alfa_off = 90
'100 - 1000Hz scale lines
FOR i = 100 TO 1000 STEP 100
alfa = 71.658589*LN(i) - 315
x2 = x1+circ.r*COS(alfa + alfa_off)*1.03
y2 = y1+circ.r*SIN(alfa + alfa_off)*1.03
DRAW LINE x1,y1 TO x2,y2
NEXT i
'1000 - 10.000Hz scale lines
FOR i = 1000 TO 10000 STEP 1000
alfa = 71.658589*LN(i) - 315
x2 = x1+circ.r*COS(alfa + alfa_off)*1.03
y2 = y1+circ.r*SIN(alfa + alfa_off)*1.03
DRAW LINE x1,y1 TO x2,y2
NEXT i
'scale: 100Hz field
f100.w = scr.w/9
f100.h = f100.w/1.8
f100.x = scr.w2 - f100.w/0.7
f100.y = scr.h2*1.57*cor_f1
FIELD "100" TEXT "" AT f100.x,f100.y SIZE f100.w,f100.h RO
FIELD "100" BACK ALPHA 0
FIELD "100" FONT SIZE f100.h*0.8*cor_f2
FIELD "100" TEXT "100"
'scale: 1000Hz field
f1000.w = scr.w/6*cor_f2
f1000.h = f1000.w/1.8
f1000.x = scr.w2 - f1000.w/3
f1000.y = scr.h2*0.32*cor_f2
FIELD "1000" TEXT "" AT f1000.x,f1000.y SIZE f100.w,f1000.h RO
FIELD "1000" BACK ALPHA 0
FIELD "1000" FONT SIZE f1000.h*0.53*cor_f1
FIELD "1000" TEXT "1000"
'scale: 10.000Hz field
f10K.w = scr.w/9
f10K.h = f10K.w/1.8
f10K.x = scr.w2 + f10K.w/1.4
f10K.y = scr.h2*1.57*cor_f1
FIELD "10K" TEXT "" AT f10K.x,f10K.y SIZE f10K.w,f10K.h RO
FIELD "10K" BACK ALPHA 0
FIELD "10K" FONT SIZE f10K.h*0.8*cor_f2
FIELD "10K" TEXT "10k"
'------------ End of Knob Dial -------------'
'herz display: field
fi.w = scr.w/1.9
fi.h = fi.w/3
fi.x = scr.w2 - fi.w/2
fi.y = scr.h*0.005
FIELD "freq" TEXT "" AT fi.x,fi.y SIZE fi.w,fi.h RO
FIELD "freq" BACK ALPHA 0.04
FIELD "freq" FONT SIZE fi.w*0.27
FIELD "freq" TEXT "Test"
'slider: sensitivity (button increment)
sl.k = 0
sl.x = scr.w2/2
sl.y = scr.h*0.9
sl.s = scr.w*0.5
sl.a = 0
SLIDER "sens" VALUE sl.k AT sl.x,sl.y SIZE sl.s ANGLE sl.a
'slider: fine-tune-field
ft.w = scr.w/2
ft.h = ft.w/8
ft.x = scr.w2 - ft.w/2
ft.y = scr.h2*1.83
FIELD "fTune" TEXT "" AT ft.x,ft.y SIZE ft.w,ft.h RO
FIELD "fTune" BACK ALPHA 0
FIELD "fTune" FONT SIZE ft.w*0.095*cor_f2
FIELD "fTune" TEXT " 1 1/3 1/5 Fine Tune"
'knob: init position
knob_ang = 15
knob_ang_old = 15
knob_ang2 = 15
knob_incr = 1
LOOP:
'slider: slide
IF SLIDER_CHANGED("sens") THEN
s.s = SLIDER_VALUE("sens")
IF s.s <= 0.33 THEN
SLIDER("sens") VALUE 0
knob_incr = 1
END IF
IF s.s > 0.33 AND s.s < 0.67 THEN
SLIDER("sens") VALUE 0.5
knob_incr = 0.3
END IF
IF s.s >= 0.67 THEN
SLIDER("sens") VALUE 1
knob_incr = 0.2
END IF
END IF
'knob: turn
'reset knob_ang_diff to stop the button
knob_ang_diff = 0
'reset first touch angle to last touch angle
knob_ang_new1 = knob_ang_new2
GET TOUCH 0 AS tx,ty
IF tx >-1 THEN
dx_t = tx - scr.w2
dy_t = ty - scr.h2
'check if touch was in button area
IF dx_t^2 + dy_t^2 < (0.45*scr.w)^2 THEN
'get first angle when (re)touching
IF first_touch = 1 THEN
knob_ang_new1 = ATAN2(dy_t,dx_t)
first_touch = 0
END IF
knob_ang_new2 = ATAN2(dy_t,dx_t)
knob_ang_diff = (knob_ang_new2 - knob_ang_new1)
'limit the max/min ang difference
IF knob_ang_diff > +12 THEN knob_ang_diff=0
IF knob_ang_diff < -12 THEN knob_ang_diff=0
ELSE
first_touch = 1
END IF
END IF
'remember last knob position
knob_ang_old = knob_ang
knob_ang = knob_ang_old + knob_ang_diff*knob_incr
'map knob angle +/- 180' -> 0-360'
knob_ang2 = knob_ang
IF knob_ang2 < 0 THEN
knob_ang2 = (knob_ang2+360)
END IF
knob_ang2 = (knob_ang2)%360
'skip not defined knob_angles
IF knob_ang2 <= 15 THEN knob_ang2 = 15
IF knob_ang2 >= 346 THEN knob_ang2 = 346
'calc. dial frequency out of the knob angle
freq_1 = 81.113083079*EXP(0.0139550612*knob_ang2)
'get best midi note fit
note_old = note
note = FLOOR(69 + 12*LOG2(freq_1/440))
note_f = 440*2^((note-69)/12)
'calc. best pitchbend value
pitchB = INT(63 +(32*12*LOG2(freq_1/note_f)))
NOTES MIDI 0,14,0,pitchB 'pitch bend
'calc. emited frequency
freq_2 = note_f*2^((pitchB-63)/(32*12))
IF note_old <> note THEN
NOTES MIDI 0,9,note,80 'play new note
NOTES MIDI 0,9,note_old,0 'stop old note
END IF
'update knob position
SPRITE "knob" AT scr.w2,scr.h2 ANGLE knob_ang2
'spacer for "centered" freq. display
spacer$ = ""
a = FLOOR(LOG10(freq_2*1000))
FOR i = 1 TO 7-a
spacer$ = spacer$&" "
NEXT i
FIELD "freq" TEXT spacer$&INT(freq_2*10)/10
GOTO LOOP