diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/g_vumeter.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/src/g_vumeter.c | 712 |
1 files changed, 0 insertions, 712 deletions
diff --git a/apps/plugins/pdbox/PDa/src/g_vumeter.c b/apps/plugins/pdbox/PDa/src/g_vumeter.c index c7b3f1f209..fb3a8fafa4 100644 --- a/apps/plugins/pdbox/PDa/src/g_vumeter.c +++ b/apps/plugins/pdbox/PDa/src/g_vumeter.c | |||
@@ -711,716 +711,4 @@ void g_vumeter_setup(void) | |||
711 | class_setsavefn(vu_class, vu_save); | 711 | class_setsavefn(vu_class, vu_save); |
712 | class_setpropertiesfn(vu_class, vu_properties); | 712 | class_setpropertiesfn(vu_class, vu_properties); |
713 | } | 713 | } |
714 | /* Copyright (c) 1997-1999 Miller Puckette. | ||
715 | * For information on usage and redistribution, and for a DISCLAIMER OF ALL | ||
716 | * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | ||
717 | |||
718 | /* g_7_guis.c written by Thomas Musil (c) IEM KUG Graz Austria 2000-2001 */ | ||
719 | /* thanks to Miller Puckette, Guenther Geiger and Krzystof Czaja */ | ||
720 | |||
721 | |||
722 | #include <stdlib.h> | ||
723 | #include <string.h> | ||
724 | #include <stdio.h> | ||
725 | #include <ctype.h> | ||
726 | #include "m_pd.h" | ||
727 | #include "g_canvas.h" | ||
728 | #include "t_tk.h" | ||
729 | #include "g_all_guis.h" | ||
730 | #include <math.h> | ||
731 | |||
732 | #ifdef MSW | ||
733 | #include <io.h> | ||
734 | #else | ||
735 | #include <unistd.h> | ||
736 | #endif | ||
737 | |||
738 | /* ----- vu gui-peak- & rms- vu-meter-display ---------- */ | ||
739 | |||
740 | t_widgetbehavior vu_widgetbehavior; | ||
741 | static t_class *vu_class; | ||
742 | |||
743 | /* widget helper functions */ | ||
744 | |||
745 | static void vu_update_rms(t_vu *x, t_glist *glist) | ||
746 | { | ||
747 | if(glist_isvisible(glist)) | ||
748 | { | ||
749 | int w4=x->x_gui.x_w/4, off=text_ypix(&x->x_gui.x_obj, glist)-1; | ||
750 | int xpos=text_xpix(&x->x_gui.x_obj, glist), quad1=xpos+w4+1, quad3=xpos+x->x_gui.x_w-w4-1; | ||
751 | |||
752 | sys_vgui(".x%x.c coords %xRCOVER %d %d %d %d\n", | ||
753 | glist_getcanvas(glist), x, quad1, off, quad3, | ||
754 | off + (x->x_led_size+1)*(IEM_VU_STEPS-x->x_rms)); | ||
755 | } | ||
756 | } | ||
757 | |||
758 | static void vu_update_peak(t_vu *x, t_glist *glist) | ||
759 | { | ||
760 | t_canvas *canvas=glist_getcanvas(glist); | ||
761 | |||
762 | if(glist_isvisible(glist)) | ||
763 | { | ||
764 | int xpos=text_xpix(&x->x_gui.x_obj, glist); | ||
765 | int ypos=text_ypix(&x->x_gui.x_obj, glist); | ||
766 | |||
767 | if(x->x_peak) | ||
768 | { | ||
769 | int i=iemgui_vu_col[x->x_peak]; | ||
770 | int j=ypos + (x->x_led_size+1)*(IEM_VU_STEPS+1-x->x_peak) | ||
771 | - (x->x_led_size+1)/2; | ||
772 | |||
773 | sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n", canvas, x, | ||
774 | xpos, j, | ||
775 | xpos+x->x_gui.x_w+1, j); | ||
776 | sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n", canvas, x, | ||
777 | iemgui_color_hex[i]); | ||
778 | } | ||
779 | else | ||
780 | { | ||
781 | int mid=xpos+x->x_gui.x_w/2; | ||
782 | |||
783 | sys_vgui(".x%x.c itemconfigure %xPLED -fill #%6.6x\n", | ||
784 | canvas, x, x->x_gui.x_bcol); | ||
785 | sys_vgui(".x%x.c coords %xPLED %d %d %d %d\n", | ||
786 | canvas, x, mid, ypos+20, | ||
787 | mid, ypos+20); | ||
788 | } | ||
789 | } | ||
790 | } | ||
791 | |||
792 | static void vu_draw_new(t_vu *x, t_glist *glist) | ||
793 | { | ||
794 | t_canvas *canvas=glist_getcanvas(glist); | ||
795 | |||
796 | int xpos=text_xpix(&x->x_gui.x_obj, glist); | ||
797 | int ypos=text_ypix(&x->x_gui.x_obj, glist); | ||
798 | int w4=x->x_gui.x_w/4, mid=xpos+x->x_gui.x_w/2, | ||
799 | quad1=xpos+w4+1; | ||
800 | int quad3=xpos+x->x_gui.x_w-w4, | ||
801 | end=xpos+x->x_gui.x_w+4; | ||
802 | int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2; | ||
803 | int led_col, yyy, i, k4=ypos-k3; | ||
804 | |||
805 | sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -tags %xBASE\n", | ||
806 | canvas, xpos-1, ypos-2, | ||
807 | xpos+x->x_gui.x_w+1, | ||
808 | ypos+x->x_gui.x_h+2, x->x_gui.x_bcol, x); | ||
809 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
810 | { | ||
811 | led_col = iemgui_vu_col[i]; | ||
812 | yyy = k4 + k1*(k2-i); | ||
813 | sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xRLED%d\n", | ||
814 | canvas, quad1, yyy, quad3, yyy, x->x_led_size, iemgui_color_hex[led_col], x, i); | ||
815 | if(((i+2)&3) && (x->x_scale)) | ||
816 | sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ | ||
817 | -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n", | ||
818 | canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize, | ||
819 | x->x_gui.x_lcol, x, i); | ||
820 | } | ||
821 | if(x->x_scale) | ||
822 | { | ||
823 | i=IEM_VU_STEPS+1; | ||
824 | yyy = k4 + k1*(k2-i); | ||
825 | sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ | ||
826 | -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n", | ||
827 | canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize, | ||
828 | x->x_gui.x_lcol, x, i); | ||
829 | } | ||
830 | sys_vgui(".x%x.c create rectangle %d %d %d %d -fill #%6.6x -outline #%6.6x -tags %xRCOVER\n", | ||
831 | canvas, quad1, ypos-1, quad3-1, | ||
832 | ypos-1 + k1*IEM_VU_STEPS, x->x_gui.x_bcol, x->x_gui.x_bcol, x); | ||
833 | sys_vgui(".x%x.c create line %d %d %d %d -width %d -fill #%6.6x -tags %xPLED\n", | ||
834 | canvas, mid, ypos+10, | ||
835 | mid, ypos+10, x->x_led_size, x->x_gui.x_bcol, x); | ||
836 | sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ | ||
837 | -font {%s %d bold} -fill #%6.6x -tags %xLABEL\n", | ||
838 | canvas, xpos+x->x_gui.x_ldx, ypos+x->x_gui.x_ldy, | ||
839 | strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:"", | ||
840 | x->x_gui.x_font, x->x_gui.x_fontsize, x->x_gui.x_lcol, x); | ||
841 | if(!x->x_gui.x_fsf.x_snd_able) | ||
842 | { | ||
843 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
844 | canvas, | ||
845 | xpos-1, ypos + x->x_gui.x_h+1, | ||
846 | xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2, | ||
847 | x, 0); | ||
848 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
849 | canvas, | ||
850 | xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1, | ||
851 | xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2, | ||
852 | x, 1); | ||
853 | } | ||
854 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
855 | { | ||
856 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
857 | canvas, | ||
858 | xpos-1, ypos-2, | ||
859 | xpos + IOWIDTH-1, ypos-1, | ||
860 | x, 0); | ||
861 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
862 | canvas, | ||
863 | xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2, | ||
864 | xpos+x->x_gui.x_w+1, ypos-1, | ||
865 | x, 1); | ||
866 | } | ||
867 | } | ||
868 | |||
869 | |||
870 | static void vu_draw_move(t_vu *x, t_glist *glist) | ||
871 | { | ||
872 | t_canvas *canvas=glist_getcanvas(glist); | ||
873 | |||
874 | int xpos=text_xpix(&x->x_gui.x_obj, glist); | ||
875 | int ypos=text_ypix(&x->x_gui.x_obj, glist); | ||
876 | int w4=x->x_gui.x_w/4, quad1=xpos+w4+1; | ||
877 | int quad3=xpos+x->x_gui.x_w-w4, | ||
878 | end=xpos+x->x_gui.x_w+4; | ||
879 | int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2; | ||
880 | int yyy, i, k4=ypos-k3; | ||
881 | |||
882 | sys_vgui(".x%x.c coords %xBASE %d %d %d %d\n", | ||
883 | canvas, x, xpos-1, ypos-2, | ||
884 | xpos+x->x_gui.x_w+1,ypos+x->x_gui.x_h+2); | ||
885 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
886 | { | ||
887 | yyy = k4 + k1*(k2-i); | ||
888 | sys_vgui(".x%x.c coords %xRLED%d %d %d %d %d\n", | ||
889 | canvas, x, i, quad1, yyy, quad3, yyy); | ||
890 | if(((i+2)&3) && (x->x_scale)) | ||
891 | sys_vgui(".x%x.c coords %xSCALE%d %d %d\n", | ||
892 | canvas, x, i, end, yyy+k3); | ||
893 | } | ||
894 | if(x->x_scale) | ||
895 | { | ||
896 | i=IEM_VU_STEPS+1; | ||
897 | yyy = k4 + k1*(k2-i); | ||
898 | sys_vgui(".x%x.c coords %xSCALE%d %d %d\n", | ||
899 | canvas, x, i, end, yyy+k3); | ||
900 | } | ||
901 | vu_update_peak(x, glist); | ||
902 | vu_update_rms(x, glist); | ||
903 | sys_vgui(".x%x.c coords %xLABEL %d %d\n", | ||
904 | canvas, x, xpos+x->x_gui.x_ldx, | ||
905 | ypos+x->x_gui.x_ldy); | ||
906 | if(!x->x_gui.x_fsf.x_snd_able) | ||
907 | { | ||
908 | sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n", | ||
909 | canvas, x, 0, | ||
910 | xpos-1, ypos + x->x_gui.x_h+1, | ||
911 | xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2); | ||
912 | sys_vgui(".x%x.c coords %xOUT%d %d %d %d %d\n", | ||
913 | canvas, x, 1, | ||
914 | xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1, | ||
915 | xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2); | ||
916 | } | ||
917 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
918 | { | ||
919 | sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n", | ||
920 | canvas, x, 0, | ||
921 | xpos-1, ypos-2, | ||
922 | xpos + IOWIDTH-1, ypos-1); | ||
923 | sys_vgui(".x%x.c coords %xIN%d %d %d %d %d\n", | ||
924 | canvas, x, 1, | ||
925 | xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2, | ||
926 | xpos+x->x_gui.x_w+1, ypos-1); | ||
927 | } | ||
928 | } | ||
929 | |||
930 | static void vu_draw_erase(t_vu* x,t_glist* glist) | ||
931 | { | ||
932 | int i; | ||
933 | t_canvas *canvas=glist_getcanvas(glist); | ||
934 | |||
935 | sys_vgui(".x%x.c delete %xBASE\n", canvas, x); | ||
936 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
937 | { | ||
938 | sys_vgui(".x%x.c delete %xRLED%d\n", canvas, x, i); | ||
939 | if(((i+2)&3) && (x->x_scale)) | ||
940 | sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i); | ||
941 | } | ||
942 | if(x->x_scale) | ||
943 | { | ||
944 | i=IEM_VU_STEPS+1; | ||
945 | sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i); | ||
946 | } | ||
947 | sys_vgui(".x%x.c delete %xPLED\n", canvas, x); | ||
948 | sys_vgui(".x%x.c delete %xRCOVER\n", canvas, x); | ||
949 | sys_vgui(".x%x.c delete %xLABEL\n", canvas, x); | ||
950 | if(!x->x_gui.x_fsf.x_snd_able) | ||
951 | { | ||
952 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); | ||
953 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1); | ||
954 | } | ||
955 | if(!x->x_gui.x_fsf.x_rcv_able) | ||
956 | { | ||
957 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); | ||
958 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1); | ||
959 | } | ||
960 | } | ||
961 | |||
962 | static void vu_draw_config(t_vu* x, t_glist* glist) | ||
963 | { | ||
964 | int i; | ||
965 | t_canvas *canvas=glist_getcanvas(glist); | ||
966 | |||
967 | sys_vgui(".x%x.c itemconfigure %xBASE -fill #%6.6x\n", canvas, x, x->x_gui.x_bcol); | ||
968 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
969 | { | ||
970 | sys_vgui(".x%x.c itemconfigure %xRLED%d -width %d\n", canvas, x, i, | ||
971 | x->x_led_size); | ||
972 | if(((i+2)&3) && (x->x_scale)) | ||
973 | sys_vgui(".x%x.c itemconfigure %xSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n", | ||
974 | canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize, | ||
975 | x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol); | ||
976 | } | ||
977 | if(x->x_scale) | ||
978 | { | ||
979 | i=IEM_VU_STEPS+1; | ||
980 | sys_vgui(".x%x.c itemconfigure %xSCALE%d -text {%s} -font {%s %d bold} -fill #%6.6x\n", | ||
981 | canvas, x, i, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize, | ||
982 | x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol); | ||
983 | } | ||
984 | sys_vgui(".x%x.c itemconfigure %xLABEL -font {%s %d bold} -fill #%6.6x -text {%s} \n", | ||
985 | canvas, x, x->x_gui.x_font, x->x_gui.x_fontsize, | ||
986 | x->x_gui.x_fsf.x_selected?IEM_GUI_COLOR_SELECTED:x->x_gui.x_lcol, | ||
987 | strcmp(x->x_gui.x_lab->s_name, "empty")?x->x_gui.x_lab->s_name:""); | ||
988 | |||
989 | sys_vgui(".x%x.c itemconfigure %xRCOVER -fill #%6.6x -outline #%6.6x\n", canvas, | ||
990 | x, x->x_gui.x_bcol, x->x_gui.x_bcol); | ||
991 | sys_vgui(".x%x.c itemconfigure %xPLED -width %d\n", canvas, x, | ||
992 | x->x_led_size); | ||
993 | } | ||
994 | |||
995 | static void vu_draw_io(t_vu* x, t_glist* glist, int old_snd_rcv_flags) | ||
996 | { | ||
997 | int xpos=text_xpix(&x->x_gui.x_obj, glist); | ||
998 | int ypos=text_ypix(&x->x_gui.x_obj, glist); | ||
999 | t_canvas *canvas=glist_getcanvas(glist); | ||
1000 | |||
1001 | if((old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && !x->x_gui.x_fsf.x_snd_able) | ||
1002 | { | ||
1003 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
1004 | canvas, | ||
1005 | xpos-1, ypos + x->x_gui.x_h+1, | ||
1006 | xpos + IOWIDTH-1, ypos + x->x_gui.x_h+2, | ||
1007 | x, 0); | ||
1008 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xOUT%d\n", | ||
1009 | canvas, | ||
1010 | xpos+x->x_gui.x_w+1-IOWIDTH, ypos + x->x_gui.x_h+1, | ||
1011 | xpos+x->x_gui.x_w+1, ypos + x->x_gui.x_h+2, | ||
1012 | x, 1); | ||
1013 | } | ||
1014 | if(!(old_snd_rcv_flags & IEM_GUI_OLD_SND_FLAG) && x->x_gui.x_fsf.x_snd_able) | ||
1015 | { | ||
1016 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 0); | ||
1017 | sys_vgui(".x%x.c delete %xOUT%d\n", canvas, x, 1); | ||
1018 | } | ||
1019 | if((old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && !x->x_gui.x_fsf.x_rcv_able) | ||
1020 | { | ||
1021 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
1022 | canvas, | ||
1023 | xpos-1, ypos-2, | ||
1024 | xpos + IOWIDTH-1, ypos-1, | ||
1025 | x, 0); | ||
1026 | sys_vgui(".x%x.c create rectangle %d %d %d %d -tags %xIN%d\n", | ||
1027 | canvas, | ||
1028 | xpos+x->x_gui.x_w+1-IOWIDTH, ypos-2, | ||
1029 | xpos+x->x_gui.x_w+1, ypos-1, | ||
1030 | x, 1); | ||
1031 | } | ||
1032 | if(!(old_snd_rcv_flags & IEM_GUI_OLD_RCV_FLAG) && x->x_gui.x_fsf.x_rcv_able) | ||
1033 | { | ||
1034 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 0); | ||
1035 | sys_vgui(".x%x.c delete %xIN%d\n", canvas, x, 1); | ||
1036 | } | ||
1037 | } | ||
1038 | |||
1039 | static void vu_draw_select(t_vu* x,t_glist* glist) | ||
1040 | { | ||
1041 | int i; | ||
1042 | t_canvas *canvas=glist_getcanvas(glist); | ||
1043 | |||
1044 | if(x->x_gui.x_fsf.x_selected) | ||
1045 | { | ||
1046 | sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); | ||
1047 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
1048 | { | ||
1049 | if(((i+2)&3) && (x->x_scale)) | ||
1050 | sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n", | ||
1051 | canvas, x, i, IEM_GUI_COLOR_SELECTED); | ||
1052 | } | ||
1053 | if(x->x_scale) | ||
1054 | { | ||
1055 | i=IEM_VU_STEPS+1; | ||
1056 | sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n", | ||
1057 | canvas, x, i, IEM_GUI_COLOR_SELECTED); | ||
1058 | } | ||
1059 | sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, IEM_GUI_COLOR_SELECTED); | ||
1060 | } | ||
1061 | else | ||
1062 | { | ||
1063 | sys_vgui(".x%x.c itemconfigure %xBASE -outline #%6.6x\n", canvas, x, IEM_GUI_COLOR_NORMAL); | ||
1064 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
1065 | { | ||
1066 | if(((i+2)&3) && (x->x_scale)) | ||
1067 | sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n", | ||
1068 | canvas, x, i, x->x_gui.x_lcol); | ||
1069 | } | ||
1070 | if(x->x_scale) | ||
1071 | { | ||
1072 | i=IEM_VU_STEPS+1; | ||
1073 | sys_vgui(".x%x.c itemconfigure %xSCALE%d -fill #%6.6x\n", | ||
1074 | canvas, x, i, x->x_gui.x_lcol); | ||
1075 | } | ||
1076 | sys_vgui(".x%x.c itemconfigure %xLABEL -fill #%6.6x\n", canvas, x, x->x_gui.x_lcol); | ||
1077 | } | ||
1078 | } | ||
1079 | |||
1080 | void vu_draw(t_vu *x, t_glist *glist, int mode) | ||
1081 | { | ||
1082 | if(mode == IEM_GUI_DRAW_MODE_MOVE) | ||
1083 | vu_draw_move(x, glist); | ||
1084 | else if(mode == IEM_GUI_DRAW_MODE_NEW) | ||
1085 | vu_draw_new(x, glist); | ||
1086 | else if(mode == IEM_GUI_DRAW_MODE_SELECT) | ||
1087 | vu_draw_select(x, glist); | ||
1088 | else if(mode == IEM_GUI_DRAW_MODE_ERASE) | ||
1089 | vu_draw_erase(x, glist); | ||
1090 | else if(mode == IEM_GUI_DRAW_MODE_CONFIG) | ||
1091 | vu_draw_config(x, glist); | ||
1092 | else if(mode >= IEM_GUI_DRAW_MODE_IO) | ||
1093 | vu_draw_io(x, glist, mode - IEM_GUI_DRAW_MODE_IO); | ||
1094 | } | ||
1095 | |||
1096 | /* ------------------------ vu widgetbehaviour----------------------------- */ | ||
1097 | |||
1098 | |||
1099 | static void vu_getrect(t_gobj *z, t_glist *glist, | ||
1100 | int *xp1, int *yp1, int *xp2, int *yp2) | ||
1101 | { | ||
1102 | t_vu* x = (t_vu*)z; | ||
1103 | |||
1104 | *xp1 = text_xpix(&x->x_gui.x_obj, glist) - 1; | ||
1105 | *yp1 = text_ypix(&x->x_gui.x_obj, glist) - 2; | ||
1106 | *xp2 = *xp1 + x->x_gui.x_w + 2; | ||
1107 | *yp2 = *yp1 + x->x_gui.x_h + 4; | ||
1108 | } | ||
1109 | |||
1110 | static void vu_save(t_gobj *z, t_binbuf *b) | ||
1111 | { | ||
1112 | t_vu *x = (t_vu *)z; | ||
1113 | int bflcol[3]; | ||
1114 | t_symbol *srl[3]; | ||
1115 | |||
1116 | iemgui_save(&x->x_gui, srl, bflcol); | ||
1117 | binbuf_addv(b, "ssiisiissiiiiiiii", gensym("#X"),gensym("obj"), | ||
1118 | (t_int)x->x_gui.x_obj.te_xpix, (t_int)x->x_gui.x_obj.te_ypix, | ||
1119 | gensym("vu"), x->x_gui.x_w, x->x_gui.x_h, | ||
1120 | srl[1], srl[2], | ||
1121 | x->x_gui.x_ldx, x->x_gui.x_ldy, | ||
1122 | iem_fstyletoint(&x->x_gui.x_fsf), x->x_gui.x_fontsize, | ||
1123 | bflcol[0], bflcol[2], x->x_scale, | ||
1124 | iem_symargstoint(&x->x_gui.x_isa)); | ||
1125 | binbuf_addv(b, ";"); | ||
1126 | } | ||
1127 | |||
1128 | void vu_check_height(t_vu *x, int h) | ||
1129 | { | ||
1130 | int n; | ||
1131 | |||
1132 | n = h / IEM_VU_STEPS; | ||
1133 | if(n < IEM_VU_MINSIZE) | ||
1134 | n = IEM_VU_MINSIZE; | ||
1135 | x->x_led_size = n-1; | ||
1136 | x->x_gui.x_h = IEM_VU_STEPS * n; | ||
1137 | } | ||
1138 | |||
1139 | static void vu_scale(t_vu *x, t_floatarg fscale) | ||
1140 | { | ||
1141 | int i, scale = (int)fscale; | ||
1142 | |||
1143 | if(scale != 0) scale = 1; | ||
1144 | if(x->x_scale && !scale) | ||
1145 | { | ||
1146 | t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist); | ||
1147 | |||
1148 | x->x_scale = (int)scale; | ||
1149 | if(glist_isvisible(x->x_gui.x_glist)) | ||
1150 | { | ||
1151 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
1152 | { | ||
1153 | if((i+2)&3) | ||
1154 | sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i); | ||
1155 | } | ||
1156 | i=IEM_VU_STEPS+1; | ||
1157 | sys_vgui(".x%x.c delete %xSCALE%d\n", canvas, x, i); | ||
1158 | } | ||
1159 | } | ||
1160 | if(!x->x_scale && scale) | ||
1161 | { | ||
1162 | int w4=x->x_gui.x_w/4, end=text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist)+x->x_gui.x_w+4; | ||
1163 | int k1=x->x_led_size+1, k2=IEM_VU_STEPS+1, k3=k1/2; | ||
1164 | int yyy, k4=text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist)-k3; | ||
1165 | t_canvas *canvas=glist_getcanvas(x->x_gui.x_glist); | ||
1166 | |||
1167 | x->x_scale = (int)scale; | ||
1168 | if(glist_isvisible(x->x_gui.x_glist)) | ||
1169 | { | ||
1170 | for(i=1; i<=IEM_VU_STEPS; i++) | ||
1171 | { | ||
1172 | yyy = k4 + k1*(k2-i); | ||
1173 | if((i+2)&3) | ||
1174 | sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ | ||
1175 | -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n", | ||
1176 | canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize, | ||
1177 | x->x_gui.x_lcol, x, i); | ||
1178 | } | ||
1179 | i=IEM_VU_STEPS+1; | ||
1180 | yyy = k4 + k1*(k2-i); | ||
1181 | sys_vgui(".x%x.c create text %d %d -text {%s} -anchor w \ | ||
1182 | -font {%s %d bold} -fill #%6.6x -tags %xSCALE%d\n", | ||
1183 | canvas, end, yyy+k3, iemgui_vu_scale_str[i], x->x_gui.x_font, x->x_gui.x_fontsize, | ||
1184 | x->x_gui.x_lcol, x, i); | ||
1185 | } | ||
1186 | } | ||
1187 | } | ||
1188 | |||
1189 | static void vu_properties(t_gobj *z, t_glist *owner) | ||
1190 | { | ||
1191 | t_vu *x = (t_vu *)z; | ||
1192 | char buf[800]; | ||
1193 | t_symbol *srl[3]; | ||
1194 | |||
1195 | iemgui_properties(&x->x_gui, srl); | ||
1196 | sprintf(buf, "pdtk_iemgui_dialog %%s VU-METER \ | ||
1197 | --------dimensions(pix)(pix):-------- %d %d width: %d %d height: \ | ||
1198 | empty 0.0 empty 0.0 empty %d \ | ||
1199 | %d no_scale scale %d %d empty %d \ | ||
1200 | %s %s \ | ||
1201 | %s %d %d \ | ||
1202 | %d %d \ | ||
1203 | %d %d %d\n", | ||
1204 | x->x_gui.x_w, IEM_GUI_MINSIZE, x->x_gui.x_h, IEM_VU_STEPS*IEM_VU_MINSIZE, | ||
1205 | 0,/*no_schedule*/ | ||
1206 | x->x_scale, -1, -1, -1,/*no linlog, no init, no multi*/ | ||
1207 | "nosndno", srl[1]->s_name,/*no send*/ | ||
1208 | srl[2]->s_name, x->x_gui.x_ldx, x->x_gui.x_ldy, | ||
1209 | x->x_gui.x_fsf.x_font_style, x->x_gui.x_fontsize, | ||
1210 | 0xffffff & x->x_gui.x_bcol, -1/*no front-color*/, 0xffffff & x->x_gui.x_lcol); | ||
1211 | gfxstub_new(&x->x_gui.x_obj.ob_pd, x, buf); | ||
1212 | } | ||
1213 | |||
1214 | static void vu_dialog(t_vu *x, t_symbol *s, int argc, t_atom *argv) | ||
1215 | { | ||
1216 | t_symbol *srl[3]; | ||
1217 | int w = (int)atom_getintarg(0, argc, argv); | ||
1218 | int h = (int)atom_getintarg(1, argc, argv); | ||
1219 | int scale = (int)atom_getintarg(4, argc, argv); | ||
1220 | int sr_flags; | ||
1221 | |||
1222 | srl[0] = gensym("empty"); | ||
1223 | sr_flags = iemgui_dialog(&x->x_gui, srl, argc, argv); | ||
1224 | x->x_gui.x_fsf.x_snd_able = 0; | ||
1225 | x->x_gui.x_isa.x_loadinit = 0; | ||
1226 | x->x_gui.x_w = iemgui_clip_size(w); | ||
1227 | vu_check_height(x, h); | ||
1228 | if(scale != 0) | ||
1229 | scale = 1; | ||
1230 | vu_scale(x, (float)scale); | ||
1231 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG); | ||
1232 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_IO + sr_flags); | ||
1233 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE); | ||
1234 | canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x); | ||
1235 | } | ||
1236 | |||
1237 | static void vu_size(t_vu *x, t_symbol *s, int ac, t_atom *av) | ||
1238 | { | ||
1239 | x->x_gui.x_w = iemgui_clip_size((int)atom_getintarg(0, ac, av)); | ||
1240 | if(ac > 1) | ||
1241 | vu_check_height(x, (int)atom_getintarg(1, ac, av)); | ||
1242 | if(glist_isvisible(x->x_gui.x_glist)) | ||
1243 | { | ||
1244 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_MOVE); | ||
1245 | (*x->x_gui.x_draw)(x, x->x_gui.x_glist, IEM_GUI_DRAW_MODE_CONFIG); | ||
1246 | canvas_fixlinesfor(glist_getcanvas(x->x_gui.x_glist), (t_text*)x); | ||
1247 | } | ||
1248 | } | ||
1249 | |||
1250 | static void vu_delta(t_vu *x, t_symbol *s, int ac, t_atom *av) | ||
1251 | {iemgui_delta((void *)x, &x->x_gui, s, ac, av);} | ||
1252 | |||
1253 | static void vu_pos(t_vu *x, t_symbol *s, int ac, t_atom *av) | ||
1254 | {iemgui_pos((void *)x, &x->x_gui, s, ac, av);} | ||
1255 | |||
1256 | static void vu_color(t_vu *x, t_symbol *s, int ac, t_atom *av) | ||
1257 | {iemgui_color((void *)x, &x->x_gui, s, ac, av);} | ||
1258 | |||
1259 | static void vu_receive(t_vu *x, t_symbol *s) | ||
1260 | {iemgui_receive(x, &x->x_gui, s);} | ||
1261 | |||
1262 | static void vu_label(t_vu *x, t_symbol *s) | ||
1263 | {iemgui_label((void *)x, &x->x_gui, s);} | ||
1264 | |||
1265 | static void vu_label_pos(t_vu *x, t_symbol *s, int ac, t_atom *av) | ||
1266 | {iemgui_label_pos((void *)x, &x->x_gui, s, ac, av);} | ||
1267 | |||
1268 | static void vu_label_font(t_vu *x, t_symbol *s, int ac, t_atom *av) | ||
1269 | {iemgui_label_font((void *)x, &x->x_gui, s, ac, av);} | ||
1270 | |||
1271 | static void vu_float(t_vu *x, t_floatarg rms) | ||
1272 | { | ||
1273 | int i; | ||
1274 | |||
1275 | if(rms <= IEM_VU_MINDB) | ||
1276 | x->x_rms = 0; | ||
1277 | else if(rms >= IEM_VU_MAXDB) | ||
1278 | x->x_rms = IEM_VU_STEPS; | ||
1279 | else | ||
1280 | { | ||
1281 | int i = (int)(2.0*(rms + IEM_VU_OFFSET)); | ||
1282 | x->x_rms = iemgui_vu_db2i[i]; | ||
1283 | } | ||
1284 | i = (int)(100.0*rms + 10000.5); | ||
1285 | rms = 0.01*(float)(i - 10000); | ||
1286 | x->x_fr = rms; | ||
1287 | outlet_float(x->x_out_rms, rms); | ||
1288 | vu_update_rms(x, x->x_gui.x_glist); | ||
1289 | } | ||
1290 | |||
1291 | static void vu_ft1(t_vu *x, t_floatarg peak) | ||
1292 | { | ||
1293 | int i; | ||
1294 | |||
1295 | if(peak <= IEM_VU_MINDB) | ||
1296 | x->x_peak = 0; | ||
1297 | else if(peak >= IEM_VU_MAXDB) | ||
1298 | x->x_peak = IEM_VU_STEPS; | ||
1299 | else | ||
1300 | { | ||
1301 | int i = (int)(2.0*(peak + IEM_VU_OFFSET)); | ||
1302 | x->x_peak = iemgui_vu_db2i[i]; | ||
1303 | } | ||
1304 | i = (int)(100.0*peak + 10000.5); | ||
1305 | peak = 0.01*(float)(i - 10000); | ||
1306 | x->x_fp = peak; | ||
1307 | outlet_float(x->x_out_peak, peak); | ||
1308 | vu_update_peak(x, x->x_gui.x_glist); | ||
1309 | } | ||
1310 | |||
1311 | static void vu_bang(t_vu *x) | ||
1312 | { | ||
1313 | outlet_float(x->x_out_peak, x->x_fp); | ||
1314 | outlet_float(x->x_out_rms, x->x_fr); | ||
1315 | vu_update_rms(x, x->x_gui.x_glist); | ||
1316 | vu_update_peak(x, x->x_gui.x_glist); | ||
1317 | } | ||
1318 | |||
1319 | static void *vu_new(t_symbol *s, int argc, t_atom *argv) | ||
1320 | { | ||
1321 | t_vu *x = (t_vu *)pd_new(vu_class); | ||
1322 | int bflcol[]={-66577, -1, -1}; | ||
1323 | int w=IEM_GUI_DEFAULTSIZE, h=IEM_VU_STEPS*IEM_VU_DEFAULTSIZE; | ||
1324 | int ldx=-1, ldy=-8, f=0, fs=8, scale=1; | ||
1325 | int ftbreak=IEM_BNG_DEFAULTBREAKFLASHTIME, fthold=IEM_BNG_DEFAULTHOLDFLASHTIME; | ||
1326 | char str[144]; | ||
1327 | |||
1328 | iem_inttosymargs(&x->x_gui.x_isa, 0); | ||
1329 | iem_inttofstyle(&x->x_gui.x_fsf, 0); | ||
1330 | |||
1331 | if((argc >= 11)&&IS_A_FLOAT(argv,0)&&IS_A_FLOAT(argv,1) | ||
1332 | &&(IS_A_SYMBOL(argv,2)||IS_A_FLOAT(argv,2)) | ||
1333 | &&(IS_A_SYMBOL(argv,3)||IS_A_FLOAT(argv,3)) | ||
1334 | &&IS_A_FLOAT(argv,4)&&IS_A_FLOAT(argv,5) | ||
1335 | &&IS_A_FLOAT(argv,6)&&IS_A_FLOAT(argv,7) | ||
1336 | &&IS_A_FLOAT(argv,8)&&IS_A_FLOAT(argv,9)&&IS_A_FLOAT(argv,10)) | ||
1337 | { | ||
1338 | w = (int)atom_getintarg(0, argc, argv); | ||
1339 | h = (int)atom_getintarg(1, argc, argv); | ||
1340 | iemgui_new_getnames(&x->x_gui, 1, argv); | ||
1341 | ldx = (int)atom_getintarg(4, argc, argv); | ||
1342 | ldy = (int)atom_getintarg(5, argc, argv); | ||
1343 | iem_inttofstyle(&x->x_gui.x_fsf, atom_getintarg(6, argc, argv)); | ||
1344 | fs = (int)atom_getintarg(7, argc, argv); | ||
1345 | bflcol[0] = (int)atom_getintarg(8, argc, argv); | ||
1346 | bflcol[2] = (int)atom_getintarg(9, argc, argv); | ||
1347 | scale = (int)atom_getintarg(10, argc, argv); | ||
1348 | } | ||
1349 | else iemgui_new_getnames(&x->x_gui, 1, 0); | ||
1350 | if((argc == 12)&&IS_A_FLOAT(argv,11)) | ||
1351 | iem_inttosymargs(&x->x_gui.x_isa, atom_getintarg(11, argc, argv)); | ||
1352 | x->x_gui.x_draw = (t_iemfunptr)vu_draw; | ||
1353 | 714 | ||
1354 | x->x_gui.x_fsf.x_snd_able = 0; | ||
1355 | x->x_gui.x_fsf.x_rcv_able = 1; | ||
1356 | x->x_gui.x_glist = (t_glist *)canvas_getcurrent(); | ||
1357 | if (!strcmp(x->x_gui.x_rcv->s_name, "empty")) | ||
1358 | x->x_gui.x_fsf.x_rcv_able = 0; | ||
1359 | if (x->x_gui.x_fsf.x_font_style == 1) | ||
1360 | strcpy(x->x_gui.x_font, "helvetica"); | ||
1361 | else if(x->x_gui.x_fsf.x_font_style == 2) | ||
1362 | strcpy(x->x_gui.x_font, "times"); | ||
1363 | else { x->x_gui.x_fsf.x_font_style = 0; | ||
1364 | strcpy(x->x_gui.x_font, "courier"); } | ||
1365 | if(x->x_gui.x_fsf.x_rcv_able) | ||
1366 | pd_bind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); | ||
1367 | x->x_gui.x_ldx = ldx; | ||
1368 | x->x_gui.x_ldy = ldy; | ||
1369 | |||
1370 | if(fs < 4) | ||
1371 | fs = 4; | ||
1372 | x->x_gui.x_fontsize = fs; | ||
1373 | x->x_gui.x_w = iemgui_clip_size(w); | ||
1374 | vu_check_height(x, h); | ||
1375 | iemgui_all_colfromload(&x->x_gui, bflcol); | ||
1376 | if(scale != 0) | ||
1377 | scale = 1; | ||
1378 | x->x_scale = scale; | ||
1379 | x->x_peak = 0; | ||
1380 | x->x_rms = 0; | ||
1381 | x->x_fp = -101.0; | ||
1382 | x->x_fr = -101.0; | ||
1383 | iemgui_verify_snd_ne_rcv(&x->x_gui); | ||
1384 | inlet_new(&x->x_gui.x_obj, &x->x_gui.x_obj.ob_pd, &s_float, gensym("ft1")); | ||
1385 | x->x_out_rms = outlet_new(&x->x_gui.x_obj, &s_float); | ||
1386 | x->x_out_peak = outlet_new(&x->x_gui.x_obj, &s_float); | ||
1387 | return (x); | ||
1388 | } | ||
1389 | |||
1390 | static void vu_free(t_vu *x) | ||
1391 | { | ||
1392 | if(x->x_gui.x_fsf.x_rcv_able) | ||
1393 | pd_unbind(&x->x_gui.x_obj.ob_pd, x->x_gui.x_rcv); | ||
1394 | gfxstub_deleteforkey(x); | ||
1395 | } | ||
1396 | |||
1397 | void g_vumeter_setup(void) | ||
1398 | { | ||
1399 | vu_class = class_new(gensym("vu"), (t_newmethod)vu_new, (t_method)vu_free, | ||
1400 | sizeof(t_vu), 0, A_GIMME, 0); | ||
1401 | class_addbang(vu_class,vu_bang); | ||
1402 | class_addfloat(vu_class,vu_float); | ||
1403 | class_addmethod(vu_class, (t_method)vu_ft1, gensym("ft1"), A_FLOAT, 0); | ||
1404 | class_addmethod(vu_class, (t_method)vu_dialog, gensym("dialog"), | ||
1405 | A_GIMME, 0); | ||
1406 | class_addmethod(vu_class, (t_method)vu_size, gensym("size"), A_GIMME, 0); | ||
1407 | class_addmethod(vu_class, (t_method)vu_scale, gensym("scale"), A_DEFFLOAT, 0); | ||
1408 | class_addmethod(vu_class, (t_method)vu_delta, gensym("delta"), A_GIMME, 0); | ||
1409 | class_addmethod(vu_class, (t_method)vu_pos, gensym("pos"), A_GIMME, 0); | ||
1410 | class_addmethod(vu_class, (t_method)vu_color, gensym("color"), A_GIMME, 0); | ||
1411 | class_addmethod(vu_class, (t_method)vu_receive, gensym("receive"), A_DEFSYM, 0); | ||
1412 | class_addmethod(vu_class, (t_method)vu_label, gensym("label"), A_DEFSYM, 0); | ||
1413 | class_addmethod(vu_class, (t_method)vu_label_pos, gensym("label_pos"), A_GIMME, 0); | ||
1414 | class_addmethod(vu_class, (t_method)vu_label_font, gensym("label_font"), A_GIMME, 0); | ||
1415 | vu_widgetbehavior.w_getrectfn = vu_getrect; | ||
1416 | vu_widgetbehavior.w_displacefn = iemgui_displace; | ||
1417 | vu_widgetbehavior.w_selectfn = iemgui_select; | ||
1418 | vu_widgetbehavior.w_activatefn = NULL; | ||
1419 | vu_widgetbehavior.w_deletefn = iemgui_delete; | ||
1420 | vu_widgetbehavior.w_visfn = iemgui_vis; | ||
1421 | vu_widgetbehavior.w_clickfn = NULL; | ||
1422 | class_setwidget(vu_class,&vu_widgetbehavior); | ||
1423 | class_sethelpsymbol(vu_class, gensym("vu")); | ||
1424 | class_setsavefn(vu_class, vu_save); | ||
1425 | class_setpropertiesfn(vu_class, vu_properties); | ||
1426 | } | ||