📄 mp.pkg
字号:
setproc _DrawLastMol {} { book=[setg @object -graph] rank=[_GetMol book book.size-1 'prev' 0] if (rank<0) {return} _DrawMol book[rank] rank} setproc _DrawPrevMol {} { book = [setg @object -graph] global bindings.GraphBook.BookArrow.rank # If no molecule was displayed we look for the first one if (rank is null) { _DrawFirstMol return } n=[_GetMol book rank 'prev' 1] if (n<0) {return} _DrawMol book[n] n} setproc _DrawNextMol {} { book = [setg @object -graph] global bindings.GraphBook.BookArrow.rank # If no molecule was displayed we look for the last one if (rank is null) { _DrawLastMol return } n=[_GetMol book rank 'next' 1] if (n<0) {return} _DrawMol book[n] n}# The play part was not checkedsetproc _PlayAtom {mode} { book=[setg @object -graph] if (![var exist 1 bindings.GraphBook.BookArrow.rank]) { printf "No atom selected\n" return } global bindings rank=bindings.GraphBook.BookArrow.rank sound =[new &signal] sound1=[new &signal] if ((mode == "one") || (mode == "norm")) { {tmin tmax} = [mpr book sound -n $rank $rank :: >] } if (mode == "upto") {{tmin tmax}=[mpr book sound -n 0 $rank :: >]} if (mode == "downto") {{tmin tmax}=[mpr book sound -n $rank book.size-1 :: >] } sound1=sound[*x,(tmin*book.dx+book.x0):(tmax*book.dx+book.x0)] # The sample frequency should be at least 8 kHz if (sound1.dx > 1/8000) {sound1.dx=1/8000} printf "start playing ...." sound play sound1 printf "stop\n"} setproc _PlaySine {} { book=[setg @object -graph] dx = book.dx # The sample frequency should be at least 8 kHz if (dx > 1/80000) {dx = 1/8000} # The duration is half a second size = int(.5/dx) s=[new &signal] s=sin(2*pi*I($size)*$@y*$dx) s.dx = dx sound play s} setbinding 'BookArrow' "{Down key = Go to First atom} \{Up key = Go to Last atom} \{Right key = Go to Next atom} \{Left key = Go to Previous atom} \{'-' = Play a sine at cursor frequency} \{'=' = Play Closest atom} \{'<' = Play reconstruction up to closest atom} \{'>' = Play reconstruction from closest atom}"setbinding 'BookArrow' GraphBook keyDown 'down' {_DrawFirstMol}setbinding 'BookArrow' GraphBook keyDown 'up' {_DrawLastMol}setbinding 'BookArrow' GraphBook keyDown 'right' {_DrawNextMol}setbinding 'BookArrow' GraphBook keyDown 'left' {_DrawPrevMol}setbinding 'BookArrow' GraphBook leave {_LeaveMol} setbinding 'BookArrow' GraphBook keyDown '-' {_PlaySine}setbinding 'BookArrow' GraphBook keyDown '=' {_PlayAtom 'one'}setbinding 'BookArrow' GraphBook keyDown '<' {_PlayAtom 'upto'}setbinding 'BookArrow' GraphBook keyDown '>' {_PlayAtom 'downto'}binding activate 'BookArrow' ## Binding to move the molecules/atoms #binding delete 'BookMove'setbinding 'BookMove' "{Shift+Left button = move molecule/atom} \{Shift+Middle button = transpose molecule/atom} \{Shift+Right button = translates molecule/atom} \{Ctrl+Left button = scale molecule/atom} \{Ctrl+Middle button = change amplitude molecule/atom}"setbinding 'BookMove' GraphBook leftButtonMotion shift {_MoveMolMotion}setbinding 'BookMove' GraphBook leftButtonDown shift {_MoveMolDown 1 1 0 0}setbinding 'BookMove' GraphBook leftButtonUp shift {_MoveMolUp} setbinding 'BookMove' GraphBook middleButtonMotion shift {_MoveMolMotion}setbinding 'BookMove' GraphBook middleButtonDown shift {_MoveMolDown 0 1 0 0}setbinding 'BookMove' GraphBook middleButtonUp shift {_MoveMolUp} setbinding 'BookMove' GraphBook rightButtonMotion shift {_MoveMolMotion}setbinding 'BookMove' GraphBook rightButtonDown shift {_MoveMolDown 1 0 0 0}setbinding 'BookMove' GraphBook rightButtonUp shift {_MoveMolUp} setbinding 'BookMove' GraphBook leftButtonMotion ctrl {_MoveMolMotion}setbinding 'BookMove' GraphBook leftButtonDown ctrl {_MoveMolDown 0 0 1 0}setbinding 'BookMove' GraphBook leftButtonUp ctrl {_MoveMolUp} setbinding 'BookMove' GraphBook middleButtonMotion ctrl {_MoveMolMotion}setbinding 'BookMove' GraphBook middleButtonDown ctrl {_MoveMolDown 0 0 0 1}setbinding 'BookMove' GraphBook middleButtonUp ctrl {_MoveMolUp} setproc _MoveMolDown {translate transpose scale amplify} { # Get the closest molecule book=[setg @object -graph] l=[setg @object -?closest @x @y] global &array bindings.GraphBook.BookMove if (l==null) { BookMove.mol=null cursor.erase=null return } {n k}=l BookMove.oldCursorMode = [_CursorMode] _CursorChange 1 BookMove.mol=book[n] BookMove.rank=n BookMove.translate=translate BookMove.transpose=transpose BookMove.scale=scale BookMove.amplify=amplify BookMove.x=@x BookMove.y=@y}setproc _MoveMolMotion {} { import args 1 bindings.GraphBook.BookMove if (BookMove.mol is null) {return} # Prepares a list of options for drawing the rectangles x=@x y=@y list="" for {k=0} (k < BookMove.mol.dim) {k=k+1} { atom=BookMove.mol[k] if (atom is null) {continue} time=atom.time freq=atom.freq chirp=atom.chirp coeff2=atom.coeff2 phase=atom.phase dt = atom.dt df = atom.df # Deal with asymetric atoms if (atom.windowShape == 'FoF' || atom.windowShape == 'exponential') { time = time+dt } if (BookMove.scale != 0) { octave=int(log2(atom.windowSize)+0.5) octave=int(octave+log2(abs(x-time))-log2(abs(BookMove.x-time)))# octave=octave+log2(abs(x-time))-log2(abs(BookMove.x-time)) windowSize=atom.windowSize atom.windowSize = max(2,2^(octave)) dt = atom.dt df = atom.df atom.windowSize=windowSize } if (BookMove.translate != 0) { time=atom.x0+atom.dx*int(0.5+(time-atom.x0+x-BookMove.x)/atom.dx) } if (BookMove.transpose != 0) { phase=phase*y/BookMove.y freq=freq*y/BookMove.y chirp=chirp*y/BookMove.y } if (BookMove.amplify != 0) { # There should be a more ergonomic relation between # the amplitude change and the mouse movement ! coeff2=coeff2*y/BookMove.y echo $coeff2 } if (k>0) {list=list+" "} list=list+"{$time $freq $dt $df $chirp}" } command="_DrawNParallelograms '$@objname' "+"{$list}" _SuperposeReplace $@objname 'molrect' "$command"}setproc _MoveMolUp {} { # Actually move the molecule/atom # if ([msge @object class Window]) return x=@x y=@y import args 1 bindings.GraphBook.BookMove if (BookMove.mol is null) { return } book=[setg @object -graph] # Limit the translation to a certain range # !!! THIS MAY HAVE TO DEPEND ON x0 and the display range if (x < 0) {x=0} if (x > book.dx*(book.signalSize-1)) {x=book.dx*(book.signalSize-1)} # Limit the transposition to a certain range # !!! THIS MAY HAVE TO DEPEND ON the display range if (y < 0) {y=0} if (y*book.dx > 0.5) {y=0.5/book.dx} for {k=0} (k < BookMove.mol.dim) {k=k+1} { atom=BookMove.mol[k] if (atom is null) {continue} if (BookMove.scale != 0) { octave=int(log2(atom.windowSize)+0.5) octave=int(octave+log2(abs(x-atom.time))-log2(abs(BookMove.x-atom.time))) atom.windowSize=max(2,2^octave) } if (BookMove.translate != 0) { atom.timeId = atom.timeId+int(0.5+(x-BookMove.x)/atom.dx) # When non-integer times will be implemented, the above line # will be replaced by the one below # atom.time = atom.time+x-BookMove.x # Should we change the phase too ? } if (BookMove.transpose != 0) { # Do not change transpose DC/Nyquist atoms if (atom.freqId!=0 && atom.freqId!=atom.freqIdNyquist) { atom.phase=atom.phase*y/BookMove.y atom.freq=atom.freq*y/BookMove.y atom.chirp=atom.chirp*y/BookMove.y } } if (BookMove.amplify != 0) { # There should be a more ergonomic relation between # the amplitude change and the mouse movement ! atom.coeff2=atom.coeff2*y/BookMove.y } } disp _CursorChange BookMove.oldCursorMode var delete 1 bindings.GraphBook.BookMove}binding activate 'BookMove'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -