File size: 2,421 Bytes
806d4b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

U0 SongPuppet(CTask *task,I64 passes)
{
  CDbgInfo *dbg_info;
  I64 i,start,end,rip,last_rip;
  CHashFun *tmpf=NULL;
  for (i=0;i<250 && TaskValidate(task);i++) {
    if (tmpf=HashFind("Song",task->hash_table,HTT_FUN))
      break;
    Sleep(1);
  }
  if (tmpf && (dbg_info=tmpf->dbg_info)) {
    start=dbg_info->body[0];
    end  =dbg_info->body[dbg_info->max_line+1-dbg_info->min_line];
    last_rip=0;
    while (TRUE) {
      i=0;
      while (TaskValidate(task) && (rip=TaskCaller(task,i++))) {
        if (start<=rip<end) {
          if (rip<last_rip && --passes<=0)
            return;
          last_rip=rip;
        }
      }
      Sleep(1);
    }
  }
}

U0 JukeSongPuppet(CTask *juke_task,I64 passes,I64 song_num,U8 *name)
{
  Bool found;
  CTask *task;
  I64 i;

  if (FileExtDot(name))
    FileExtRem(name);
  BirthWait(&juke_task->popup_task);
  TaskWait(juke_task->popup_task);
  PostMsg(juke_task->popup_task,MSG_KEY_DOWN_UP,0,SC_CURSOR_UP+SCF_CTRL);
  TaskWait(juke_task->popup_task);
  for (i=0;i<song_num;i++) {
    PostMsg(juke_task->popup_task,MSG_KEY_DOWN_UP,0,SC_CURSOR_RIGHT);
    TaskWait(juke_task->popup_task);
  }

  PostMsg(juke_task->popup_task,MSG_KEY_DOWN_UP,CH_SPACE,0);
  TaskWait(juke_task->popup_task);
  Sleep(500);

  found=FALSE;
  task=Fs->next_task;
  while (task!=Fs) {
    if (!StrCmp(task->task_title,name)) {
      found=TRUE;
      break;
    }
    task=task->next_task;
  }

  if (found) {//Position cursor on song title during song
    TaskWait(juke_task->popup_task);
    PostMsg(juke_task->popup_task,MSG_KEY_DOWN_UP,0,SC_CURSOR_UP+SCF_CTRL);
    TaskWait(juke_task->popup_task);
    for (i=0;i<song_num;i++) {
      PostMsg(juke_task->popup_task,MSG_KEY_DOWN_UP,0,SC_CURSOR_RIGHT);
      TaskWait(juke_task->popup_task);
    }
    SongPuppet(task,passes);
  }
  Kill(task);
}

public U0 JukeSongsPuppet(U8 *dirname="~/Psalmody",I64 passes=2,
                        I64 start_song=0,I64 end_song=I64_MAX)
{//Help make music video by puppeting JukeBox task.
  I64 i;
  CDirEntry *tmpde,*tmpde1;
  CTask *juke_task=User("JukeBox(0x%X);\n",dirname);
  Cd(dirname);
  tmpde1=FilesFind("*",FUF_RECURSE|FUF_JUST_TXT|FUF_JUST_FILES);
  for (tmpde=tmpde1,i=0;tmpde && i<start_song;i++)
    tmpde=tmpde->next;
  for (i=start_song;tmpde && i<end_song;i++) {
    JukeSongPuppet(juke_task,passes,i,tmpde->name);
    tmpde=tmpde->next;
  }
  DirTreeDel(tmpde1);
  Kill(juke_task);
}