태그: 슈퍼콜라이더 댓글 스레드 토글 전환 | 키보드 단축키

  • mortp February 29, 2012 9:45 pm 퍼머링크 | 응답
    태그: 슈퍼콜라이더, , makingclass, , , writingclass   

    SC에서 클래스 만들기 

    <SC의 클래스만들기 규칙>

    Platform.systemExtensionDir;   // Extensions available to all users on the machine, .rtf가 아니라, .sc로 저장해서 여기에 넣으면 됩니다.

    home/library/applicationsupport/supercollider/extensions 에 저장 후 cmd + k

    0. 한글 주석 사용 불가

    1. Getter vs Setter

    <는 클래스 외부에서 변수의 값을 불러올 수 있게. (Getter)

    >는 클래스 외부에서 변수의 값을 변경할 수 있게. (Setter)

    <> 두개 동시에 가능

    2. classvar vs var

    classvar 는 클래스 차원에서 접근이 가능하고, (Cc.classvar이름)

    var는 인스턴스 차원에서만 접근이 가능하다. (a = Cc.new; a.var이름)

    3. ‘메소드’ =  ‘함수’라고 생각해도 무방.

    둘 모두 그 이름을 불렀을 때 수행될 일들을 적어놓는 곳.

    클래스에 대해 적용될 함수는 정의되는 이름앞에 *을 붙이고, 인스턴스에 대해 적용될 함수는 *를 붙이지 않는다.

    4. ^(꺾쇠)표시는 다른 언어에서의 ‘return’과 같은 의미.

    뒤따라 나오는 구문의 결과값을, 함수를 부른(실행하라고 명령한) 곳으로 돌려준다.

    5. 인스턴스 메소드와 클래스 메소드를 구분짓는 것은, SC(혹은 그것의 모태인 smalltalk)만의 특징인 듯.

    SC의 클래스 구조에는 별도의 생성자(Constructor)개념이 없고, 기본적으로 상속받게 되는 최상위의 Object 클래스의 메소드를 빌려 필요한 메모리 공간 등을 할당받는 구조로 보임. Object 클래스의 내용을 이용하는 일종의 생성자 개념.

    Object.new;

    //새로운 인스턴스를 할당한다. 어떤 클래스든 실제로 인스턴스를 만들어 내기 위해서는 이것이 꼭 필요하다.

    새로 정의되는 어떠한 클래스라도 그것을 실제 사용할 수 있는 인스턴스로 만들기 위해서는 위와같은 명령이 반드시 필요. 관습적으로 쓰여지는 아래와 같은 .new라는 메소드의 내용은 최소한 위와 같은 동작을 수행하기 위해서이다.

    *new{

    //new라는 이름으로 생성의 역할을 정의하는 것은 다른 클래스들과의 통일성으로보면 당연하지만 다른 이름이어도 상관 없을 듯.

    ^ super.new; //Object.new 를 하는것과 마찬가지.

    }

    여기에 클래스만의 특별한 초기화 조건을 덫붙이기 위해서는,
    Object.new와 동시에 수행될 인스턴스 함수를 정의하여 실행한다.

    *new{

    ^ super.new.init(500, 0.5, 0.7); //Object.new + 그로인해 만들어진 인스턴스.init(아규먼트에 각각 500, 0.5, 0.7)

    }

    init{arg f = 200, a = 1.0, p = 1.0; //init는 그저 initialize 역할임을 표기하기 위한 이름. 다른 이름이어도 상관 없음.

    var freq, amp, pan;

    freq = f;

    amp = a;

    pan = p;

    }

    6. 실습코드

    
    Mtr{
    
    // classvar
    
    var <>routine, <>bpm, <>amp, <>tick, <>synth, <>synthNode, <>intv;
    
    *new{| argbpm, argamp, argtick = 4, argsynth = \default |
    
    ^super.new.play(argbpm, argamp, argtick, argsynth);
    
    }
    
    
    
    play{| argbpm, argamp, argtick, argsynth |
    
    bpm = argbpm;
    
    amp = argamp;
    
    tick = argtick;
    
    synth = argsynth;
    
    routine = fork{
    
    inf.do{| i |
    
    if(i % tick == 0,
    
    {
    
    intv = 60000 / bpm; //millisecond
    
    synthNode = Synth.new(synth, [\freq, 700, \amp, amp]);
    
    },
    
    {synthNode = Synth.new(synth, [\amp, amp]);});
    
    ((intv/1000)/2).wait;
    
    synthNode.free;
    
    ((intv/1000)/2).wait;
    
    }
    
    };
    
    }
    
    
    
    stop{
    
    routine.stop;
    
    synthNode.free;
    
    }
    
    }
    
     
    • mortp 2월 29, 2012 9:59 pm 퍼머링크 | 응답

      엔터를 쳐도 줄간격이 안늘어나요 이런;;;

    • joynimm 3월 1, 2012 1:01 am 퍼머링크 | 응답

      this 가 뭐라그랬져? ^ 는 리턴…
      요즘 느끼는 바는 sc 같은 oop에서는 class 작성을 배워두면 많이 유용할 듯합니다.

      • mortp 3월 1, 2012 2:18 pm 퍼머링크 | 응답

        this는,
        클래스메소드를 정의할 때 쓰면 클래스를,
        인스턴스메소드를 정의할 때 쓰면 인스턴스를 참조한다고 하네요.
        음.. super와 대비되는 개념으로 생각하면 될 것 같아요.

  • mortp February 22, 2012 8:45 pm 퍼머링크 | 응답
    태그: Document, 슈퍼콜라이더, , ,   

    내일의 시간 절약을 위해 공부 할 코드를 미리… 

    내일의 시간 절약을 위해,

    공부(?)할 코드를 미리 올려둘게요.

    우선은 startup.rtf 파일로 저장해 주세요.

    
    s = Server.internal;
    
    Server.default = s;
    
    s.boot;
    
    
    CocoaDocument.defaultFont_(Font("Arial Unicode MS",16)); //set default font
    
    
    s.doWhenBooted
    
    {
    
    var ranNum = 0;
    
    var postWindow = Document.listener;
    
    
    //set post window
    
    postWindow.font_(Font("Arial Unicode MS",16)); //set post window default font
    
    Document.postColor_(Color.white);
    
    postWindow.background_(Color.new255(10, 20, 100, 180));
    
    postWindow.bounds_(Rect.new(0, 270, 290, 768 - 270 ));
    
    
    //set own colorize theme
    
    Document.themes.put
    
    (\myTheme,
    
    (
    
    classColor: Color.new255(53, 74, 237),
    
    textColor: Color.new255(25, 175, 120),
    
    stringColor: Color.new255(96, 129, 158),
    
    commentColor: Color.new255(206, 27, 28),
    
    symbolColor: Color.new255(57, 154, 20),
    
    numberColor: Color.new255(157, 80, 65)
    
    )
    
    );
    
    
    //and then calling setTheme with the name:
    
    Document.setTheme('myTheme');
    
    
    //document setting(문서가 새로 만들어지거나, open 할 때의 설정)
    
    Document.initAction_({
    
    Document.current.background_(Color.new255(10, 20, 20, 230));
    
    Document.current.stringColor_(Document.themes.myTheme.textColor);
    
    Document.current.selectedBackground_(Color.new255(220, 180, 150, 60)); //selected block color
    
    Document.current.syntaxColorize;
    
    Document.current.endFrontAction_({ //문서가 뒤로 갈 때의 액션을 정해 둠
    
    Document.current.background_(Color.new255(80, 20, 30, 150));
    
    });
    
    Document.current.toFrontAction_({ //문서가 앞으로 나올 때의 액션을 정해 둠
    
    Document.current.background_(Color.new255(10, 20, 20, 230));
    
    });
    
    });
    
    
    " ".postln;
    
    " ".postln;
    
    " ".postln;
    
    " ".postln;
    
    " ".postln;
    
    " ".postln;
    
    
    //run s.meter
    
    //SCLevelIndicator.meter_Xpos = 290; //set X pos, 쓰시려면 좀 더 수정이 필요해서 일단 주석처 합니다
    
    //SCLevelIndicator.meter_Ypos = 0; //set Y pos, 쓰시려면 좀 더 수정이 필요해서 일단 주석처 합니다
    
    s.meter;
    
    
    //run FreqScope
    
    //SCFreqScopeWindow.scopeXpos = 650; //set Freq Scope's X pos, 쓰시려면 좀 더 수정이 필요해서 일단 주석처 합니다
    
    //SCFreqScopeWindow.scopeYpos = 3; //set Freq Scope's Y pos, 쓰시려면 좀 더 수정이 필요해서 일단 주석처 합니다
    
    FreqScope.new(300, 200);
    
    
    //run T-D Scope
    
    //SCStethoscope.stethXpos = 1023; //set T - D Scope's X pos, 쓰시려면 좀 더 수정이 필요해서 일단 주석처 합니다
    
    //SCStethoscope.stethYpos = 8; //set T - D Scope's Y pos, 쓰시려면 좀 더 수정이 필요해서 일단 주석처 합니다
    
    SCStethoscope.new(s, 2);
    
    
    " ".postln;
    
    " ".postln;
    
    
    
    //print welcome message
    
    ranNum = 3.rand;
    
    switch(ranNum,
    
    0, {"HOW ARE YOU, GANG IL ?".postln;},
    
    1, {"IS EVERYTHING ARIGHT ?".postln;},
    
    2, {"HOW'S THE THINGS GOING ?".postln;}
    
    );
    
    
    
    " ".postln;
    
    " ".postln;
    
    " ".postln;
    
    " ".postln;
    
    };
    
    
    
    //---------------- auto colorizing -------------------
    
    Document.globalKeyDownAction_({| doc, char, mod, unicode, keycode |
    
    if((doc.name.find("htm").isNil) and: (doc.name.find("html").isNil) and: (doc.isListener == false),
    
    {
    
    if((unicode==13) or: (unicode==32) or: (unicode==46), // Enter, Space bar, Period
    
    {
    
    doc.syntaxColorize;
    
    })
    
    });
    
    });
    
    

    아래는 간단히 용어에 대한 정리 입니다.

     

    <용어 정리>

     

    -Document

    : 슈퍼콜라이더에서 ‘문서’. 우리가 지금 보고있는 편집창.

    이것 역시 클래스로 이루어져 있고, 창을 연다는 것은 이 클래스의 인스턴스를 생성하는 셈.

    따라서 정의된 속성(Properties)을 변경하거나, 함수(Method, Function)를 이용하여 어떤 일을 시킬 수 있다.

    Document 를 선택하고 cmd + y를 눌러보자.

     

    -listener

    :Document의 메소드 중 하나. post창을 의미한다.

    클래스에 직접 적용하는 class method, 인스턴스에 적용해야 하는 instance method 는 모두 클래스의 헬프파일에 설명되고 있다.

     

    -bounds

    :GUI를 이용하는, 혹은 GUI와 관련된 클래스들은 보통 bounds라는 속성을 가지는데,

    이것은 GUI 창의 좌측 하단 모서리의 x축 상의 위치,  y축 상의 위치(화면의 아랫쪽이 좌표 0), 창의 넓이, 창의 높이 정보를 말한다.

    실제로는 대부분,

    Rect(xPos, yPos, width, height);

    이런 식으로, Rect 클래스의 인스턴스를 타입으로 요구한다.

     

    -theme

    :Document의

    classColor: Color.new255(53, 74, 237),

    textColor: Color.new255(25, 175, 120),

    stringColor: Color.new255(96, 129, 158),

    commentColor: Color.new255(206, 27, 28),

    symbolColor: Color.new255(57, 154, 20),

    numberColor: Color.new255(157, 80, 65)

     

    에 대한 속성을 짝지워 담고 있는 저장공간으로,

    슈퍼콜라이더에서 사용되는 여섯 종류의 글자들이 syntaxColorize 됐을 경우 바뀔 색을 미리 지정한다.

    Event 라는 클래스의 인스턴스이다.

     

    -initAction

    :새로운 Document를 만들거나 기존의 Document를 열었을 때에, 자동으로 실행될 행동들을 예약해 두겠다는 메소드.

     
c
새 글 작성
j
다음 글/다음 댓글
k
이전 글/이전 댓글
r
응답
e
편집
o
댓글 표시/숨기기
t
상위로 가기
l
로그인하기
h
도움말 표시/숨기기
shift + esc
취소